RE: Question about function call stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No, you can never make that assumption.  Every different port of GCC
uses a different calling sequence.  Sometimes switches will change the
calling sequence.  Some ABI's will pass nothing in registers (i386
classic), some will pass the first few arguments in certain registers
depending on the type of the arguments, some will pass some things on
the stack and other things in registers.

The standard way to write your program is to convert it to use stdarg.h,
and use va_arg to get at the arguments.  Be sure that the variable
argument function is properly declared, since some ports have different
calling sequences for functions with a fixed number of arguments and
with a variable number.

--
Michael Meissner
AMD, MS 83-29
90 Central Street
Boxborough, MA 01719

-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Emmanuel Pacaud
Sent: Tuesday, January 17, 2006 10:33 AM
To: gcc-help@xxxxxxxxxxx
Subject: Question about function call stack

Hi,

In a project I'm working on, I've to fix an issue which is dependant on 
the target platform.

You'll find below a code snippet that shows the issue. When compiled for

a 32 bit platform, with gcc 3.2.2, I get the expected behaviour, which 
is the following output:

0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9

But, if compiled for a 64 bit platform, with gcc 3.4.3, output is:

1 548682058152 4194884 0 -72340172838076673 0 0 1 2 3
0 1 2 3 4 5 6 7 8 9

Here's my question:

Is the assumption made in code snippet that pushing an ulong array on 
the stack, then retrieving values via function arguments correct ?

Regards,

       Emmanuel.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux