2

I am working in a C program in Code::Blocks. I am using the function printf and I am not including the <stdio.h> header however the program runs well. How do I enable warning to not miss the header?

Thank you in advance for your time and help,

Pavel
  • 5,374
  • 4
  • 30
  • 55
Roman
  • 33
  • 5
  • 4
    Did you set warning flags? I don't know how it is done in CodeBlocks, but should be somewhere in the project properties. I recommend "-Wall -Wextra -pedantic" – Ilya Popov Dec 10 '16 at 18:10
  • Are you including some other header file that already includes stdio.h? – Dai Dec 10 '16 at 18:15
  • 1
    @Dai it works well without stdio... http://ideone.com/LpAs5P – Pavel Dec 10 '16 at 18:16
  • 3
    Maybe it's because you're using old C compiler? According to this http://stackoverflow.com/a/336825/6131611 answer, newest C standard (C99) doesn't allow use functions in this way – Pavel Dec 10 '16 at 18:23
  • 2
    It'd be helpful if you show your code. – Sanjay-sopho Dec 10 '16 at 18:23
  • If you're using GCC, you could add options like `-Wmissing-prototypes`, `-Wstrict-prototypes`, `-Wold-style-declaration`, `-Wold-style-definition` (along with `-Wall -Wextra -Werror`, and maybe `-pedantic`, and sometimes `-Wshadow` and … well, there are a lot of possibilities). The `-Wmissing-prototypes` will trigger complaints if `printf()` is not declared. The `-Wstrict-prototypes` won't allow `int main() { … }` (neither will `-Wold-style-definition`), requiring `int main(void) { … }`. I compile with those options set all the time. – Jonathan Leffler Dec 10 '16 at 19:42
  • What @Dai meant was that you might have included stdio without explicitly doing it. It might be included by another header file, which you did include – Yan Zhou Dec 10 '16 at 21:46
  • Does flags written by Jonathan work? – Pavel Dec 10 '16 at 21:51
  • 1
    why you don't write answer guys? – Stargateur Dec 11 '16 at 02:22

0 Answers0