From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 4B6AC3952515 for ; Thu, 8 Dec 2022 00:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4B6AC3952515 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id gh17so229817ejb.6 for ; Wed, 07 Dec 2022 16:38:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZVTF3XnFR65pE9+yFxR7pGIKVeknppXn48rVqo/3u54=; b=ef/omNklm5udO8nesxQaW3BorfH7VqEWw6ubWRudHXr05QsqDBEwH397c5u4Gi3ngJ Uimo7mBgAO3rwysIxnsjMmCJ/M9sDiGejxeszU6Eg2gHpZk778/zsqDVOxA5AuRx5t4h IAQWRH8kSjblrqtKnZllrPtNQRFB52/Nj1O57yB3ObWQUrPRr9D0YcvK9kMXKbFQla3B 5y+0QWEhdTmLkeH4dDq0UEbUGun/K9q/xQnXIJGX6+5H424PML1xyTTZjliKBtYwY0zm T3YBkXLLBKh0spRccmtgbqiSFZTB7+Mm92mM9jxWflml+CGfYCvFpqvopOhUTL86Q8M/ ygGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZVTF3XnFR65pE9+yFxR7pGIKVeknppXn48rVqo/3u54=; b=iQDK+pd8T0jxsIer3TcEY9ruNCf82ku7kOSKnyCwlhwF6xrJa7dQWSs8SIwt+4etCZ ggvY6t+IKrbn700H3nq8ynOeGPKSqosQbz2QE+wiNbWzy2obyzK86f0/yjp3AbGVlxvV 813rrpXLyreLYwrJa3DeP6RJeeMw8eYuUyJ49Xh1H9b7eeQbg5Mm40efm27lVgFRZkS8 halEPYkyI3EvSgoBt2HBs5yS1lumhhJIpOwR6EJIl2bNa3eSGojWEdramv8tKBn72jLG /qdYxPnvooJTON1E6OFki9dLhE8JtpNPftMVNK/wCAVA/OEOrbZASD/Y8g0Q+G7jHdqi +KZA== X-Gm-Message-State: ANoB5pl96278SUHV5TNqG4pDlx9bidP6IGJ2WbKpLpJ6umvzi8jpfigX QMtJ31YGReyrQOKY4HMZMp0Ga95lyByZkr9q7Ko= X-Google-Smtp-Source: AA0mqf5hwkaCntYZcL9QefqZr77qHunHpgayoiK5ljnUFXfVKnmasTVB+3Mn0npDX7q0JdqcBOafxiIQh74Ie4tdJ5g= X-Received: by 2002:a17:906:9bed:b0:7c1:31d:315 with SMTP id de45-20020a1709069bed00b007c1031d0315mr9293634ejc.389.1670459894836; Wed, 07 Dec 2022 16:38:14 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 8 Dec 2022 00:38:02 +0000 Message-ID: Subject: Re: XOPEN, POSIX and BSD defines in C vs. C++ code To: Tom Kacvinsky Cc: gcc-help Content-Type: multipart/alternative; boundary="000000000000a4b3a905ef4640fa" X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000a4b3a905ef4640fa Content-Type: text/plain; charset="UTF-8" On Wed, 7 Dec 2022, 23:13 Tom Kacvinsky via Gcc-help, 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 > > 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 > --000000000000a4b3a905ef4640fa--