thread.h is name pollution ?

C

Chris Dollin

Ian said:
Hi All,

Just illustrating my lack of C knowledge again:

Wot now ? cat test.c
#include <pthread.h>

void thread_init( void ){}

Wot now ? xlc_r -c -qlanglvl=stdc89 test.c
"test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from previous declaration on line 886 of "/usr/include/sys/thread.h".
"test.c", line 3.6: 1506-376 (I) Redeclaration of thread_init has a different number of fixed parameters than the previous declaration.
Wot now ? xlc_r -c -qlanglvl=stdc99 test.c
"test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from previous declaration on line 886 of "/usr/include/sys/thread.h".
"test.c", line 3.6: 1506-376 (I) Redeclaration of thread_init has a different number of fixed parameters than the previous declaration.

In sys/thread.h thread_init is declared as

void thread_init(unsigned long long, unsigned long long)

and the -qlanglvl flags above ask the compiler to at least report deviations
from the c89 and c99 standards respectively.

Is the implementation allowed by the standard to reserve this part of the namespace ?

You've included a non-standard header; the (C) standard doesn't prohibit non-standard
headers from eating names that the standard headers don't eat.

I see your compiler doesn't remark on the non-standardness of <pthread.h>.
 
R

Richard Heathfield

Ian Bush said:
Hi All,

Just illustrating my lack of C knowledge again:

Wot now ? cat test.c
#include <pthread.h>

void thread_init( void ){}

Wot now ? xlc_r -c -qlanglvl=stdc89 test.c
"test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from
previous declaration on line 886 of "/usr/include/sys/thread.h". "test.c",

In sys/thread.h thread_init is declared as

void thread_init(unsigned long long, unsigned long long)

and the -qlanglvl flags above ask the compiler to at least report
deviations from the c89 and c99 standards respectively.

Is the implementation allowed by the standard to reserve this part of the
namespace ?

No, unless you invite it to do so, by - for example - including a
non-standard header such as <pthread.h>.
 
I

Ian Bush

Hi All,

Just illustrating my lack of C knowledge again:

Wot now ? cat test.c
#include <pthread.h>

void thread_init( void ){}

Wot now ? xlc_r -c -qlanglvl=stdc89 test.c
"test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from previous declaration on line 886 of "/usr/include/sys/thread.h".
"test.c", line 3.6: 1506-376 (I) Redeclaration of thread_init has a different number of fixed parameters than the previous declaration.
Wot now ? xlc_r -c -qlanglvl=stdc99 test.c
"test.c", line 3.6: 1506-343 (S) Redeclaration of thread_init differs from previous declaration on line 886 of "/usr/include/sys/thread.h".
"test.c", line 3.6: 1506-376 (I) Redeclaration of thread_init has a different number of fixed parameters than the previous declaration.

In sys/thread.h thread_init is declared as

void thread_init(unsigned long long, unsigned long long)

and the -qlanglvl flags above ask the compiler to at least report deviations
from the c89 and c99 standards respectively.

Is the implementation allowed by the standard to reserve this part of the namespace ?

Ian
 
I

Ian Bush

Richard said:
Ian Bush said:


No, unless you invite it to do so, by - for example - including a
non-standard header such as <pthread.h>.

Yeah, thanks Richard and Chris I should have realized that myself.

I'll have to see what pthreads says now,

Ian
 
T

Tom St Denis

Ian said:
Yeah, thanks Richard and Chris I should have realized that myself.

I'll have to see what pthreads says now,

Of course it may be worth pointing out that functions like
"thread_init" are about as descript as

void function(...)

If the thread has a purpose [say spooling to printer] call it

int spool_thread_init(...) { }

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top