Re: Doubt



Anarki wrote:

int main(a,b,c,d,e,f,g)

You are using the so-called "old style" function definition without a
declaration list specifying the types of the parameters. In such a case
they default to type int.

Further note that unless your implementation specifically defines this
form of main, (i.e., int main(int, int, int, int, int, int, int)), you
are invoking undefined behaviour.

{
printf("Size of a = %d\nSize of b =%d",sizeof(a),sizeof(b));

The sizeof operator yields a value of type size_t. The 'd' type
specifier is for int values. Use 'z' if available, or 'lu' and cast to
unsigned long.

return 0;
}

The above program perfectly compiles in cygwin using gcc

and my questions are

1.How does the compiler know what are the types of variables a, b, c,
d, e, f and g?? Where is its declaration?

As above.

2.I haven't included stdio.h yet the printf compiles.The compiler
doesn't complain about the requirement of function prototype, why?

If you had invoked your compiler in conforming mode then it would have.
For gcc use the -ansi/-std=c99 and -pedantic flags for C90 or C99
conformance. C99 conformance is incomplete.

.



Relevant Pages

  • Exporting function in VS2008 DLL
    ... I am picking up some differences between VS2003 and VS2008/05's C++ compiler ... in handling export functions in unmanaged DLL and am wondering if this is a ... definition of the function in the other module as dllexport. ... I do not have to include the dllexport in function definition ...
    (microsoft.public.vc.language)
  • Re: strange function syntax
    ... > device libraries have a function definition that looks like this: ... > (everything works fine w/o optimization). ... This could be a compiler problem ...
    (comp.lang.c)
  • Re: What is going on here?
    ... In article, Karl Heinz Buchegger ... > with the function definition, for the compiler it has not. ... > empty statement. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Function with unspecified number of arguments
    ... int main ...     return 0; ... you just don't tell the compiler how many. ... you wrote a function definition: ...
    (comp.lang.c)