Software Archive
Read-only legacy content

c99 issue

newport_j
Beginner
1,061 Views

I am asI said in a previous post trying to compile my code in c99 or in the c99 standard andI got the following errors. (I am attaching time.h) it was included in each function that hadgenerated an error.

clock_gettime declared implicitly and CLOCK_REALTIME undefined.

Ialso had in an include file:

typedef struct timespec TIME_SPEC;

and TIME_SPEC now1, now2;


and TIME_SPECtimeout;

ineach case I got the rror

"incomplete type is not allowed",

referring to now1,now2,and timeout.

I know this is again a c99 vs. earlier version of c issue and I would like to solve it.

Any help appreciated and thanks in advance.

Newport_j
0 Kudos
2 Replies
BradleyKuszmaul
Beginner
1,061 Views
Come on Newport_j, get in the habit of filing *complete* bug reports. Exactly what was your input file? Exactly what was the compile command line? Exactly what was the error message? Is it different with gcc?
0 Kudos
newport_j
Beginner
1,061 Views


I have a program that keeps time on its executions.

I use the header file time.h, which I include in my own header file WAFmutex.h.

In WAFmutex.h I included the line:

Typedef struct timespec TIME_SPEC;

In a *.c source file I have the following lines of code:

TIME_SPEC now1, now2;

clock_gettime(CLOCK_REALTIME, &now1);


In the first line which compiles under c, the error when I include std=c99 in my icc compiler commands is

Error: incomplete type is not allowed with karat under now1 and now2.

TIME_SPEC now1, now2;

And the second line gives the error:

Error: identifier CLOCK_REALTIME is undefined;

and,

warning: the following message clock_gettime is declared implicitly.

Now when I compile with gcc the errors are:

TIME_SPEC now1, now2;

clock_gettime(CLOCK_REALTIME, &now1);


In the first line which compiles under c, the error when I include std=c99 in my compiler commands is

Error: storage size of now1 is unknown,

Error: storage size of now2 is unknown,

and for the second line

clock_gettime(CLOCK_REALTIME, &now1);

warning: implicit declaration of function 'clock_gettime'

and

CLOCK_GETTIME is undeclared. First use in this function.


Again, these lines are no problemfor either icc or gcc, until I use -std=c99 in my command line. Then these errors and warning show. These code lines are clearly not compatible with c99.

What changes should I make in my c code to get rid of this warning, and to get rid of the errors? I assume the changes in the c code will get rid of thewarning and errorsfor both the gcc and icc compilers.

I shed the errors for the icc compiler and then the gcc compiler. Anything not clear let me know,I will be happy to answer.

Thanks in advance.

Newport_j

0 Kudos
Reply