"Rahul" <sa*****@yahoo.co.inwrote in message
news:50**********************************@i72g2000 hsd.googlegroups.com...
Hi Everyone,
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
However, why doesn't this extend to a global variable which isn't
declared? The compiler gives as error immediately...
Thanks in advance!!!
that error may have crept into the old C because the compiler could do some
sort of
code generation for a function call, but not for variables.
if function f() is not defined (and not declared in its prototype form -
this is important), the
compiler assumes the form "int f()" , which to very likely to be incorrect,
because the actual definition may be
say void f(int,float). The compiler has generated code at the point of call
for a function with "int" return and
no arguments. Whereras the function expects an int and float (maybe on
stack, or in registers), but does not return anything.
A runtime disaster, no doubt but mericifully detected by linker
In contrast, what code can the compiler generate for an undeclared variable
? None, because the compiler not
psychic to know the type of the variable from its usage !