different output from the gcc

David Korn dkorn@pixelpower.com
Mon Oct 16 09:37:00 GMT 2000


>> the following program prints different outputs on the terminal.
>>
>> #include <stdio.h>
>> int main()
>> {
>>     int i=10, j=20;
>>     printf("%d %d");
>>     return 0;
>> }
>>
>>
>> on windows nt, prints : 38076236 1627415320
>> on RH linux    , prints : 20 10
>> on sun solaris , prints : 67584 -1341572
>
>Are you sure you don't mean  printf("%d %d", i, j) ?
>
>If you don't provide the arguments corresponding to
>the printf control string, printf just scoops up
>whatever happens to be on the stack, which is 
>(expectedly) system dependant.  Or am I missing
>something?

  Roughly. Under some calling conventions, the first <n> arguments are
passed in registers. I would guess that Linux does that, and so printf
is getting the old values in those registers, which had been used as
temporaries for i and j; the other systems are passing stack crud.

        DaveK
-- 
 "The secret of life is honesty and fair dealing. If you can fake that,
you've got it made." -Groucho Marx


More information about the Gcc-help mailing list