User forums > General (but related to Code::Blocks)

dont want by default #include's

(1/3) > >>

jguarin2002:
Hello everyone

Im having this compiler directives class and I am the instructor. I want to illustrate the students what is and why is necessary the #include directive etc...

The problem is that in theory if I do not include the stdio.h header then -beside other functions- I wont have printf declared and therefore I cant make any calls to it. However -in a classical hello world example- when I cut off this line from the code (the #include <stdio.h> directive) the building does not complain and works fine, and it should because of the printf("hello world\n"); line on the code. There is no errors, even warnings or whatsoever.

I guess this is a CodeBlocks feature, but i dont know how to turn it off. How do i do that? I mean I want to make explicit the #include <stdio.h>.

killerbot:
that's not CB, the compiler should complain, and I think it will.

I assume you teaching C ???

See the result of new console project from Cb (C language) :

Where I commented out the 2 includes (note the stdlib.h is not even needed !!!! NOTE to self : adjust our code)



--- Quote ---int main()
{
    printf("Hello world!\n");
    return 0;
}

--- End quote ---

This is the compiler output CB shows -> apparently warnings  :shock: :shock: :shock:


--- Quote ----------------- Build: Debug in DelMe ---------------
Compiling: main.c
/home/killerbot/Projects/DelMe/main.c: In function ‘main’:
/home/killerbot/Projects/DelMe/main.c:6: warning: implicit declaration of function ‘printf’
/home/killerbot/Projects/DelMe/main.c:6: warning: incompatible implicit declaration of built-in function ‘printf’
Linking console executable: bin/Debug/DelMe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 2 warnings

--- End quote ---

But hey, code should also b warning free. Maybe there's a setting you can specify to  the (GCC) compiler, where such a things should be treated as an error, but I don't know if there is one.

TDragon:
It's not a C::B feature; it's part of the C standard, which allows functions to be "implicitly" declared -- i.e. assumed to have a return value of "int" and argument types that match the ones passed.

Note: The C99 standard no longer allowed for implicit function declarations, which is why a warning is emitted. To turn the warning into an error, you can add the GCC parameter "-Werror-implicit-function-declaration".

jguarin2002:
u r right. Yeah. Both of you are right. But....

Im using mingw as compiler on win32.

However in Linux it will complain with a warning at least (i know mingw is a win32 gcc port, but still a port), im used more to linux than to windows (nothing against windows).

But, if, for example. You declare something like a FILE *, it will complain with an error.

Ok. So till where the C standard stands to?. printf will not complain if not included stdio.h but FILE * will cry whenever stdio.h is not declared.

What do you think?. I apreciate your comments, thank you.
julian

killerbot:
I have done the same on windows Xp with GCC 3.4.5, also here I get a warning :


--- Quote ----------------- Build: Debug in DelMe ---------------
[ 50.0%] Compiling: main.c
C:\Projects\DelMe\main.c: In function `main':
C:\Projects\DelMe\main.c:5: warning: implicit declaration of function `printf'
[100.0%] Linking console executable: ..\Deliv\Debug\DelMe.exe
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 1 warnings
Build log saved as: C:\Projects\DelMe\DelMe_build_log.html

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version