Is it better to #define _BSD_SOURCE or to set CPPFLAGS=-D_BSD_SOURCE?
It seems to me that if a piece of source 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With