So, this is code from a student of my friend…
#include <stdio.h>
int main(){
int hours;
int take_one_number(void);{
scanf("%d",&hours);
}
int minutes;
int take_one_number(void);{
scanf("%d",&minutes);
}
int seconds;
int take_one_number(void);{
scanf("%d",&seconds);
}
int all;
printf("%d",all=hours*3600+minutes*60+seconds);
return all;
}
Well, it… compiles… and… uhm, works… as requested by the teacher…
My question: if I understand correctly, take_one_number
here is a definition of a variable to store a function pointer. Why does neither GCC nor LLVM complain about a duplicated identifier in these definitions?
The function take_one_number is declared 3 times, but never defined. In each case, the ; after the (void) ends the declaration. The scanf statement is then just a regular statement inside of main(), surrounded by a meaningless scope { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With