Why does gcc ignore __attribute__((stdcall))?
Asked Answered
P

1

8

When I compile the following C source with gcc version 8.1.1, I get a warning: ‘stdcall’ attribute ignored [-Wattributes].

Why does gcc choose to ignore this attribute and what can I do to make it accept it?

__attribute__((stdcall)) int S(int a) {
    return a * (a+1);
}

int main() {
    return S(6);
}
Pigeontoed answered 9/10, 2018 at 5:23 Comment(2)
What architecture are you compiling for?Syphilis
Move to a 32-bit x86 platform.Suicide
L
8

The gcc documentation says:

stdcall

On x86-32 targets, the stdcall attribute causes the compiler to assume that the called function pops off the stack space used to pass arguments, unless it takes a variable number of arguments.

(Emphasis mine.)

So if you're not compiling for a 32-bit machine, stdcall can't be used.

Lysis answered 9/10, 2018 at 5:29 Comment(4)
Is there a technical reason that stdcall is not possible on non-x86-32 targets?Unbridled
@RenéNyffenegger x86-64 doesn't pass arguments on the stack (or rather, it prefers using registers before using the stack), so there's little point in defining and using different incompatible conventions for adjusting the stack.Lysis
Thanks for clearing that up to me. I was completely unaware of the shift between 32 and 64 bit x86 regarding calling conventions.Unbridled
Is it possible to turn this warning off?Halfslip

© 2022 - 2024 — McMap. All rights reserved.