Should standards be specified in source code or in CPPFLAGS?

Is it better to #define _BSD_SOURCE or set CPPFLAGS = -D_BSD_SOURCE?

It seems to me that if part of the source code depends on a specific standard, it is best to specify it explicitly in the C # define code itself. However, many comments indicate that defining a compilation line standard is more appropriate. What are the benefits of excluding a standard from source code and specifying it only at compile time?

+6
c ++ c build-process compilation
source share
1 answer

If you specify the definitions in your source, there is a risk that the same header file may be included in several source files (translation units), but with different preprocessor definitions, which can lead to violation of the One Definition rule, which is often a pain debugging.

By defining definitions for the entire project, rather than in separate source files, the likelihood of such a violation of a rule of a certain value is minimized.

In addition, if it becomes necessary to add a new definition, you only modify one makefile, not all the source files.

+6
source share

All Articles