What does -D_XOPEN_SOURCE do/mean?

后端 未结 4 477
自闭症患者
自闭症患者 2020-11-29 19:33

I recently encountered some code that gcc would not compile without this arg. I checked the gcc man page, but did not find this specific option. I did find XOPEN_SOURC

4条回答
  •  無奈伤痛
    2020-11-29 20:01

    -D is a c compiler option to define a preprocessor variable. In this case _XOPEN_SOURCE.

    This doesn't actually affect the behavior of the compiler itself, but rather changes how some libraries, e.g. the standard c library, behave. There are several options like this. In most cases they are in relation to some standard document about some UNIX specific programming interface, or some specific library vendor.

    Defining one of them is sometimes necessary, because the behavior of some standard functions or even their signature can differ between standards. So you might have to use -D_XOPEN_SOURCE or something similar to turn on a compatibility mode.

    Another possible usage of these flags is to make sure your source code stays within the limits of a certain standard, by turning of extensions offered by your C library implementation. This is one of the measures you could use to make sure that your code runs on as many platforms as possible.

提交回复
热议问题