Re: gettid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The default C++ mode, when no -std= is specified, for g++ 9.3.0 is
gnu++14 (it's the same for g++ 10.1.0, too).

> Looks like it is set by default, even when specifying the C++ standard version for g++
Why this happens is explained in libstd++'s faq:
https://gcc.gnu.org/onlinedocs/libstdc++/faq.html#faq.predefined


On Wed, Jun 17, 2020 at 12:14 PM Jonny Grant <jg@xxxxxxxx> wrote:
>
>
>
> On 17/06/2020 11:22, Jakub Wilk wrote:
> > * Jonny Grant <jg@xxxxxxxx>, 2020-06-16, 12:36:
> >> SYNOPSIS         top
> >>   #define _GNU_SOURCE
> >>   #include <unistd.h>
> >>   #include <sys/types.h>
> >>
> >>   pid_t gettid(void);
> >>
> >> I can compile on Ubuntu without #define _GNU_SOURCE and call gettid()
> >>
> >> Maybe that line can be removed?
> >
> > I don't think so. Here's what I get (with GCC 9):
> >
> >   $ gcc test.c
> >   test.c: In function ‘main’:
> >   test.c:6:9: warning: implicit declaration of function ‘gettid’; did you mean ‘getgid’? [-Wimplicit-function-declaration]
> >       6 |  return gettid();
> >         |         ^~~~~~
> >         |         getgid
> >
> > Prepending "#define _GNU_SOURCE" fixes the above.
>
> Hi Jakub,
>
> Apologies, I should have shared my test case, I was compiling as C++
> // g++ -Wall -o tid tid.cpp
>
> #include <unistd.h>
> #include <sys/types.h>
>
> int main()
> {
>     return gettid();
> }
>
>
>
> $ g++ -Wall -o tid tid.cpp
> tid.cpp:3: warning: "_GNU_SOURCE" redefined
>     3 | #define _GNU_SOURCE
>       |
> <command-line>: note: this is the location of the previous definition
>
>
> Looks like it is set by default, even when specifying the C++ standard version for g++
> g++ -std=c++11 -Wall -o tid tid.cpp
>
>
> Checked, yes, if compiling as C, see the same result as you.
>
> Not sure how it gets enabled by default in my c++
>
> $ g++ --version
> g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0
>
> Cheers, Jonny
>
>


--
Regards,
Ponnuvel P




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux