Doubt

A

Anarki

int main(a,b,c,d,e,f,g)
{
printf("Size of a = %d\nSize of b =%d",sizeof(a),sizeof(b));
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?
2.I haven't included stdio.h yet the printf compiles.The compiler
doesn't complain about the requirement of function prototype, why?
 
I

Ian Collins

Anarki said:
int main(a,b,c,d,e,f,g)
{
printf("Size of a = %d\nSize of b =%d",sizeof(a),sizeof(b));
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?

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

It does.

gcc /tmp/x.c
/tmp/x.c: In function 'main':
/tmp/x.c:3: warning: incompatible implicit declaration of built-in
function 'printf'
 
A

Anarki

It's assuming they are int.


It does.

gcc /tmp/x.c
/tmp/x.c: In function 'main':
/tmp/x.c:3: warning: incompatible implicit declaration of built-in
function 'printf'

y no warning for me! ok if at all it complains how does this program
link with the printf? Does it look in default include files/libs ??

By the way I use Cygwin(windows Xp) is there a way to redirect the
warning/errors to a text file. If so please tell me how
 
S

santosh

Anarki said:
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.
 
S

santosh

Please snip signatures unless you are commenting on them.
y no warning for me! ok if at all it complains how does this program
link with the printf? Does it look in default include files/libs ??

A compiler is allowed to do whatever it wants after emitting the
required diagnostics, including making guesses about what you meant and
trying to generate the best possible code.
By the way I use Cygwin(windows Xp) is there a way to redirect the
warning/errors to a text file. If so please tell me how

Use:

gcc -whatever_flags_you_want file_list_etc 2> errors.txt

Now all diagnostic messages will be redirected to a file named
errors.txt.

Using 2>> instead of 2> will append the output of the command to the
existing contents of errors.txt.

For more help ask in a Unix group like comp.unix.programmer or on the
mailing lists for Cygwin.
 
S

santosh

Richard said:
santosh said:


Chapter and verse for C90, please. (I accept that your claim is
correct for C99.)

<snip>

Um, does 0.0 p0 qualify? :)

You're right. The rules of C90 do not require a diagnostic. This is what
comes of relying more on gcc than on the Standard document itself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top