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]

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.

#include <stdio.h>
#include <stdlib.h>

#define SIZE 10

void
f (ulong v1, ulong v2, ulong v3, ulong v4, ulong v5, ulong v6, ulong v7, ulong v8, ulong v9, ulong v10)
{
	printf ("%li %li %li %li %li %li %li %li %li %li \n",
		v1, v2, v3, v4, v5, v6, v7, v8, v9, v10);
}

typedef struct {
	ulong array[SIZE];
} Stack;

void
g (Stack stack)
{
	int i;

	for (i = 0; i < SIZE; i++)
		printf ("%li ", stack.array[i]);
	printf ("\n");
}

int 
main (int argc, char *argv[]) 
{
	void (*function_ptr) ();
	Stack stack;
	int i;

	for (i = 0; i < SIZE; i++)
		stack.array[i] = i;
	
	function_ptr = f;
	(*function_ptr) (stack);
	function_ptr = g;
	(*function_ptr) (stack);

  	exit(0);
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]