All of lore.kernel.org
 help / color / mirror / Atom feed
* gettid
@ 2020-06-16 11:36 Jonny Grant
  2020-06-17 10:22 ` gettid Jakub Wilk
  0 siblings, 1 reply; 5+ messages in thread
From: Jonny Grant @ 2020-06-16 11:36 UTC (permalink / raw)
  To: Michael Kerrisk; +Cc: linux-man

Hello mtk

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?

https://www.man7.org/linux/man-pages/man2/gettid.2.html

Cheers
Jonny

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

* Re: gettid
  2020-06-16 11:36 gettid Jonny Grant
@ 2020-06-17 10:22 ` Jakub Wilk
  2020-06-17 11:14   ` gettid Jonny Grant
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Wilk @ 2020-06-17 10:22 UTC (permalink / raw)
  To: Jonny Grant; +Cc: Michael Kerrisk, linux-man

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

* Jonny Grant <jg@jguk.org>, 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.

-- 
Jakub Wilk

[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 99 bytes --]

#include <unistd.h>
#include <sys/types.h>

int main(int argc, char **argv)
{
	return gettid();	
}

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

* Re: gettid
  2020-06-17 10:22 ` gettid Jakub Wilk
@ 2020-06-17 11:14   ` Jonny Grant
  2020-06-17 12:10     ` gettid Ponnuvel Palaniyappan
  0 siblings, 1 reply; 5+ messages in thread
From: Jonny Grant @ 2020-06-17 11:14 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: Michael Kerrisk, linux-man



On 17/06/2020 11:22, Jakub Wilk wrote:
> * Jonny Grant <jg@jguk.org>, 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



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

* Re: gettid
  2020-06-17 11:14   ` gettid Jonny Grant
@ 2020-06-17 12:10     ` Ponnuvel Palaniyappan
  2020-06-17 12:26       ` gettid Jonny Grant
  0 siblings, 1 reply; 5+ messages in thread
From: Ponnuvel Palaniyappan @ 2020-06-17 12:10 UTC (permalink / raw)
  To: Jonny Grant; +Cc: Jakub Wilk, Michael Kerrisk, linux-man

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@jguk.org> wrote:
>
>
>
> On 17/06/2020 11:22, Jakub Wilk wrote:
> > * Jonny Grant <jg@jguk.org>, 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

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

* Re: gettid
  2020-06-17 12:10     ` gettid Ponnuvel Palaniyappan
@ 2020-06-17 12:26       ` Jonny Grant
  0 siblings, 0 replies; 5+ messages in thread
From: Jonny Grant @ 2020-06-17 12:26 UTC (permalink / raw)
  To: Ponnuvel Palaniyappan; +Cc: Jakub Wilk, Michael Kerrisk, linux-man



On 17/06/2020 13:10, Ponnuvel Palaniyappan wrote:
> 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

Fair enough

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

end of thread, other threads:[~2020-06-17 12:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16 11:36 gettid Jonny Grant
2020-06-17 10:22 ` gettid Jakub Wilk
2020-06-17 11:14   ` gettid Jonny Grant
2020-06-17 12:10     ` gettid Ponnuvel Palaniyappan
2020-06-17 12:26       ` gettid Jonny Grant

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.