public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* XOPEN, POSIX and BSD defines in C vs. C++ code
@ 2022-12-07 23:12 Tom Kacvinsky
  2022-12-08  0:38 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Kacvinsky @ 2022-12-07 23:12 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 927 bytes --]

Hi,

I ran into a rather interesting issue today.  I noticed that if I run
(with GCC 12.1)

gcc -x c -std=c17 -dM -E foo.c

where foo.c is simply

#include <features.h>

I don't get any of the XOPEN, POSIX or BSD defines that features.h would
typically
set based on -D options passed to the compiler.

However, if I run

gcc -x c++ -std=c++17 -dM -E foo.c

I get definitions like

#define _XOPEN_SOURCE 700.

I find this curious - I thought compilers were supposed to be OS standards
agnostic
(but obviously not language standards agnostic).

I am using a glibc 2.17 system, if that makes any difference.  I don't see
anything in
features.h that would indicate _XOPEN_SOURCE should be defined if the
compiler
is a C++ compiler conforming to the C++17 standard (for instance).

Any ideas as to what is going on here?  Is this expected behavior, as in
something in
the C++ standard I am unaware of, or is it a bug?

Thanks,

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: XOPEN, POSIX and BSD defines in C vs. C++ code
  2022-12-07 23:12 XOPEN, POSIX and BSD defines in C vs. C++ code Tom Kacvinsky
@ 2022-12-08  0:38 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-12-08  0:38 UTC (permalink / raw)
  To: Tom Kacvinsky; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]

On Wed, 7 Dec 2022, 23:13 Tom Kacvinsky via Gcc-help, <gcc-help@gcc.gnu.org>
wrote:

> Hi,
>
> I ran into a rather interesting issue today.  I noticed that if I run
> (with GCC 12.1)
>
> gcc -x c -std=c17 -dM -E foo.c
>
> where foo.c is simply
>
> #include <features.h>
>
> I don't get any of the XOPEN, POSIX or BSD defines that features.h would
> typically
> set based on -D options passed to the compiler.
>
> However, if I run
>
> gcc -x c++ -std=c++17 -dM -E foo.c
>
> I get definitions like
>
> #define _XOPEN_SOURCE 700.
>
> I find this curious - I thought compilers were supposed to be OS standards
> agnostic
> (but obviously not language standards agnostic).
>
> I am using a glibc 2.17 system, if that makes any difference.  I don't see
> anything in
> features.h that would indicate _XOPEN_SOURCE should be defined if the
> compiler
> is a C++ compiler conforming to the C++17 standard (for instance).
>
> Any ideas as to what is going on here?  Is this expected behavior, as in
> something in
> the C++ standard I am unaware of, or is it a bug?
>

It's expected but nothing to do with the standard. The C++ standard has
nothing to say about POSIX macros.

On glibc Linux systems libstdc++ depends on some gnu extensions in glibc.
In order to ensure that those extensions can be used, g++ automatically
defines _GNU_SOURCE. That causes glibc to define all POSIX APIs, including
those macros.





> Thanks,
>
> Tom
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-08  0:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 23:12 XOPEN, POSIX and BSD defines in C vs. C++ code Tom Kacvinsky
2022-12-08  0:38 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).