This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Question about function call stack


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@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Emmanuel Pacaud
Sent: Tuesday, January 17, 2006 10:33 AM
To: gcc-help@gcc.gnu.org
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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]