Bug 33660 - gettid has not been declared
Summary: gettid has not been declared
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.1
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-04 18:33 UTC by Sergey A. Razin
Modified: 2007-10-04 20:05 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test case (171 bytes, application/octet-stream)
2007-10-04 18:35 UTC, Sergey A. Razin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey A. Razin 2007-10-04 18:33:56 UTC
Hello!

Upgraded to gcc 4.2.1 and ran into a following issue:
test case:
#include <iostream>
#include <sstream>
#include <sys/types.h>
#include <linux/unistd.h>
#include <errno.h>
// Declare the gettid syscall.
_syscall0(pid_t, gettid);
int main()
{
        std::cout<<"Test for gettid: "<<std::gettid()<<endl;
        return 0;
}

It works on gcc 3.6. Incluede all the proper header according to man pages, but compiler returns:
getid.cpp:10: error: ‘gettid’ has not been declared
getid.cpp:10: error: expected constructor, destructor, or type conversion before ‘;’ token
getid.cpp: In function ‘int main()’:
getid.cpp:16: error: ‘gettid’ was not declared in this scope

Sergey
Comment 1 Sergey A. Razin 2007-10-04 18:35:41 UTC
Created attachment 14296 [details]
test case
Comment 2 Andrew Pinski 2007-10-04 18:40:09 UTC
And this is not a bug with GCC or libstdc++ as gettid is an GNU libc extension.

Try using gettid instead of std::gettid.  Doing that and qualifying endl with std:: allows for this program to compile.
Comment 3 Wolfgang Bangerth 2007-10-04 18:41:45 UTC
Why should gettid be in namespace std? It's not a standard C++ function,
so the header file declares it to be in the global namespace.

W.
Comment 4 Sergey A. Razin 2007-10-04 18:46:41 UTC
(In reply to comment #3)
> Why should gettid be in namespace std? It's not a standard C++ function,
> so the header file declares it to be in the global namespace.
> 
> W.
> 

(In reply to comment #3)
> Why should gettid be in namespace std? It's not a standard C++ function,
> so the header file declares it to be in the global namespace.
> 
> W.
> 

Ok. That's just the test. I can remove namespace completely:

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

int main()
{
        gettid();
        return 0;
}

Same result. Actually I figured it will bring up questions, sor
Comment 5 Sergey A. Razin 2007-10-04 19:37:27 UTC
Ok. That's just the test. I can remove namespace completely:

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

int main()
{
        gettid();
        return 0;
}

Same result. Actually I figured it will bring up questions, sorry
Comment 6 Paolo Carlini 2007-10-04 20:05:19 UTC
Try asking for help on some Linux mailing list, because gettid is (or was) a Linux extension, actually. In any case, what is available or not on such system headers has nothing to do with GCC.