Jenia Be Nice Please
Jenia Be Nice Please

Reputation: 2693

gcc not giving warning even with -Wall flag

I call the function timer_settimer with an argument of type timer_t* (a pointer) or timer_t and gcc compiles both versions. Doesn't give any error or nothing else.

void initialize_timer(timer_t * tid, int seconds)
    ...
    timer_settime(*tid, 0, ts, NULL) == -1;
    OR
    timer_settime(tid, 0, ts, NULL) == -1;

No error no nothing. (the first version works correctly. the second bugs). This is my Makefile:

all: 
    gcc -Wall -ggdb -lrt  -pthread -o jenia_thread thread.c  

How can I make gcc output all the warnings?

Thanks in advance.

Upvotes: 1

Views: 380

Answers (1)

Keith Thompson
Keith Thompson

Reputation: 263517

The type timer_t is defined as void*. Specifically, on my system, I have:

typedef void * __timer_t;
...
typedef __timer_t timer_t;

(You have to go several levels deep in system include files to find this; I compiled a small program with gcc -E to see the preprocessed source with all the includes expanded.)

Your system most likely has something similar, particularly if you're using the GNU C library.

The first parameter of timer_settime is of type timer_t, or void* -- which means that an argument of any pointer-to-object or pointer-to-incomplete type will be implicitly converted to void* and not require a compile-time diagnostic.

It's an unfortunate choice, and one that doesn't seem to be imposed by POSIX. You'll just have to be careful to pass an argument of the right type without any help from the compiler.

Upvotes: 2

Related Questions