J
João Jerónimo
I came across a strange bug today. I had a function declared this way:
sthread_mon_t sthread_monitor_init();
But mistakenly called it as:
sthread_monitor_init(requests_monitor);
So, the return value was discarded and the object (a mutual-exclusive
monitor) was not initialized, which in turn caused a Segmentation Fault.
The problem is: the compiler[1] swallowed the source without complaining,
which felt strange, because the function was declared (or at least I
thought so) as taking no arguments, and so that call was malformed.
Then, I changed the prototype to:
sthread_mon_t sthread_monitor_init(void);
and this time the compiler complained about the signature mismatch.
Can you explain me this (subtle) difference between the two declarations? I
thought they meant the samething. I'm using -Wall and -std=c99, but not
-pedantic.
[1] gcc-4.1.2
JJ
sthread_mon_t sthread_monitor_init();
But mistakenly called it as:
sthread_monitor_init(requests_monitor);
So, the return value was discarded and the object (a mutual-exclusive
monitor) was not initialized, which in turn caused a Segmentation Fault.
The problem is: the compiler[1] swallowed the source without complaining,
which felt strange, because the function was declared (or at least I
thought so) as taking no arguments, and so that call was malformed.
Then, I changed the prototype to:
sthread_mon_t sthread_monitor_init(void);
and this time the compiler complained about the signature mismatch.
Can you explain me this (subtle) difference between the two declarations? I
thought they meant the samething. I'm using -Wall and -std=c99, but not
-pedantic.
[1] gcc-4.1.2
JJ