printf function help

Chris Gehlker plug-devel@lists.PLUG.phoenix.az.us
Sat Mar 6 16:23:02 2004


On Mar 6, 2004, at 2:59 PM, Tarun Karra wrote:

> hi ,
> =A0
> thanx for the help on printf..
> sorry for delay in getting back to you..
> even i agree that its a ***stupid question****, but one of my friends=20=

> had to answer this in an interview and i wanted to find out the=20
> answer..
> =A0
> SO It prints out a garbage value off the stack..
> I agree that its a garbage value, but i dont think its out of stack..
> correct me if any of my assumptions are wrong...
> unless all the empty uninitalized values (above stack pointer)contain=20=

> SAME GARBAGE VALUES.
> =A0
> because when i add some local variables to the program it still prints=20=

> out the same garbage value.Below 2 programs print same garbage value=20=

> out..
> =A0
> #include <stdio.h>
> void main()
> {
> printf("%d");
> }
> =A0
> #include <stdio.h>
> void main()
> {
> int x =3D 10;
> int y=3D99;
> printf("%d");
> }
> =A0
> =A0
> Any way even i dont want to waste time in finding out the answer. It=20=

> may be as some one suggested that its printing garbage value from=20
> va_list, va_ptr etc.. or "results are unpredictable from IBM=20
> manuals.."
> =A0
> thanx a lot for the help and time
> tarun

I'd take the phrase 'off the stack'  to be somewhat metaphorical these=20=

days. The time when you could look at some C and know what the compiler=20=

was going to produce is gone. Nonetheless, I would be very surprised if=20=

the two assignments in your second example actually produced any code=20
even on a 70's era compiler. I would expect them to be optimized away.

Let me suggest that you learn how to view disassembly from your chosen=20=

compiler. It can make it very easy to answer this type of question.=