Is it better to #define _BSD_SOURCE or to set CPPFLAGS=-D_BSD_SOURCE?
It seems to me that if a piece of source 开发者_JS百科code relies on a particular standard, it is best to spell it out explicitly in the code itself with a #define. However, a lot of commentary suggests that specifying the standard on the compile line is more appropriate. What are the advantages of omitting the standard from the source code and only specifying it at compile time?
If you specify defines in your source there is a risk that the same header file can be included in several source files (translation units) but with different preprocessor definitions, which can lead to One Definition Rule violation which is often a pain to debug.
By specifying defines for the whole project rather than in the individual source files the chance of such One Definition Rule violation is minimized.
Also, if a need arises to add a new define, you change only one makefile, rather than all the source files.
精彩评论