struct timespec in ANSI C

I am trying to compile ANSI C code for Sun Solaris V8.

My problem is that the 'timespec' structure does not seem to be recognised when compiling. The compiler usually gives me an 'invalid reference' warning.

The funny thing is that it doesn't seem to have an effect on the run-time behaviour. Supposedly 'timespec' is defined in <time.h>, so I do have this included.

Any takers? :slight_smile: Thx in advance.

The only solaris 8 system that I have access to has no compiler, so I can't test this. But looking at the include files, <time.h> will include <sys/time_impl.h> depending on what symbols you set. <sys/time_impl.h> defines timespec.

My guess is that you are defining symbols that are removing non-posix and/or non-ansi-c definitions from the namespace. And the header files are not handling your selected options in a robust manner. If you are getting a compile error and you picked an legal combination of symbols, then the header files may have a minor bug. As a work-around, maybe you can define timespec in a typedef to silence the compiler.

Thanks for the advice Perderabo - I think you're right. I'm going through most of my definitions ATM to make sure there are no conflicts.

What makes me think you're right is that compiling without the '-Xc' switch (ANSI C conformance in Sun CC) leads to no warnings. Certainly an interesting one.

I seem to remember having similiar issues with the time structure myself.

I can't remember whether I was porting code from unix to windows, or from one type of unix to another or (most likely) recompiling on a higher version of HP-UX.

It seems the time.h and its structures are not standard across the board and you may have to compile slightly different code based on your environment.

As Perderabo suggests you may need to examine the different compile switchs already available in your headers, or

use your own pre-processor directives to conditionally compile code, or

write your own time functions and use them instead.

MBB