Altera_Forum
Honored Contributor
17 years agoVerilog conditional compilation: `defines and `ifdefs
There was a helpful thread (http://www.alteraforum.com/forum/showthread.php?t=1996) about configuring `defines in .qsf file. I use conditional compilation to optionally remove parts of code from compilation, usually for debugging purposes. I used it for some time but recently I've come across a little puzzle.
Suppose I have two files, top.v and foobar.v. top.v defines a module top that uses foobar defined in foobar.v. The code in foobar is braced by `ifdef USE_FOOBAR. Now, the question is if i put `define USE_FOOBAR at the top of top.v, will it guarrantee that USE_FOOBAR will be defined when the compiler reaches foobar.v? It seems that it will not, but I can't figure out when it works and when it does not. I have a rather complex project where it definitely works and a pretty simple one where it doesn't, but I don't see a pattern.