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

dont want by default #include's

<< < (2/3) > >>

killerbot:
and when adding the GCC option as suggested above I get an error :


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

So all seems to be ok to me.

rcoll:
What, exactly, are you asking?

The C standard states (up to C99, anyway) that a function call with no prototype will be assumed to take the arguments given on the first invocation and return an int result.

This fits perfectly with your call to printf(). 

However, your declaration with FILE is not a function call, it is a variable declaration.  Since FILE has not yet been defined anywhere (stdio.h not included) the compiler issues an error.

For a more complete (if blistering) explanation, you should ask this question on comp.lang.c

Ringo

jguarin2002:

--- Quote ---function call with no prototype will be assumed to take the arguments given on the first invocation and return an int result
--- End quote ---

Ok. Let me see if i got it: So after first call of the unprototyped printf, subsequent printf invocations should have the same arguments number is'nt it?. If im right should not this code complain about argument mismatch?: The first call to printf is clearly misnumbering the second printf call, breaking the c99 rule? What im missing?



--- Code: ---int main()
{

printf("The return value of printf(\" Hello world\"); is %d!\n",printf("Hello world\n") );

return 0;
}

--- End code ---

by the way... it did not crash complain or anything.

TDragon:
The important thing to note, here, is that you're implicitly declaring a built-in function. Certain C runtime functions are built in to GCC itself rather than being pulled from the system's C runtime -- and GCC 3.4.5 allows the use of these built-ins without even a warning (yeah, I tested it just now :P).

As you've seen, this is not an entirely optimal situation; this is fixed in the GCC 4 series, which emits a warning when you do it.

killerbot:
GCC 3.4.5 also gave a warning , see a reply of mine with log above

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version