Hi!
I have succesfully used regparm attribute in function declarations when compiling with gcc 3.3.2. Then I switched to gcc 3.4.2 and things seem to have changed, because in 3.4.2 my code does not compile. Here's some code:
test.c
int c;
int d;
void test(int a, int b) __attribute__ ((regparm(3)));
void test(int a, int b)
{
c = a + b;
}
int main(void)
{
test(c,d);
return 0;
}
I compile this with gcc 3.3.2 like this:
gcc test.c -S
and I receive asm dump as I should.. great. Here's that:
.file "test.c"
.text
.globl test
.type test, @function
test:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movl %eax, -4(%ebp)
movl %edx, -8(%ebp)
movl -8(%ebp), %eax
addl -4(%ebp), %eax
movl %eax, c
leave
ret
.size test, .-test
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl d, %edx
movl c, %eax
call test
movl $0, %eax
leave
ret
.size main, .-main
.comm c,4,4
.comm d,4,4
.ident "GCC: (GNU) 3.3.2"
Clearly it passes parameters for test in registers eax and edx and test clearly receives it's parameters correctly. Fine..
Now switch to 3.4.2:
gcc test.c -S
test.c:6: error: conflicting types for 'test'
test.c:3: error: previous declaration of 'test' was here
test.c:6: error: conflicting types for 'test'
test.c:3: error: previous declaration of 'test' was here
What happened? Only way around this is to use -mregparm=3 switch. This implies that ALL calls should be made with that calling convention, including ones to the libraries. Not good.
So finally, my question is: What I have missed? Why regparm attribute does not work anymore as it used to?
Thanks in advance! I'm really lost with this.
[Edited by - Winograd on November 5, 2004 12:36:59 AM]