Calling convention specifiers and function pointers.

D

DrTodd13

If "void (__cdecl *)()" is a pointer to a function whose calling
convention is cdecl then what are:

void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();

GCC happily accepts all these permutations.
 
E

Eric Sosman

DrTodd13 said:
If "void (__cdecl *)()" is a pointer to a function whose calling
convention is cdecl then what are:

void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();

GCC happily accepts all these permutations.

__cdecl and __stdcall aren't part of C, so they're
probably GCC extensions. Check the GCC documentation for
their meanings, alone and in combination.
 
G

gwowen

If "void (__cdecl *)()" is a pointer to a function whose calling
convention is cdecl then what are:

void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();

GCC happily accepts all these permutations.

GCC 4.4.1 rejects the third with the error

"stdcall and cdecl attributes are not compatible"

and considers the first two compatible pointer types (they can be
freely assigned to one another, even at the highest warning levels).
So it would seem the first two declare the same type, and the third is
an illegal construct (that earlier gcc's fail to diagnose).
 
N

Nobody

If "void (__cdecl *)()" is a pointer to a function whose calling
convention is cdecl then what are:

void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();

GCC happily accepts all these permutations.

I'm curious as to why it would accept a declaration without any
identifiers.

I could imagine it accepting the above as types (e.g. in casts or as
parameter types in a function declaration), but not as statements.

Perhaps you could try posting *actual code* which it accepts. If you
create a source file containing just the above three lines, I very much
doubt that gcc will compile it.

BTW, gcc itself uses function attributes, e.g. "__attribute__(cdecl)", for
specifying calling conventions. It's possible that some header file
defines __cdecl and __stdcall as macros, but gcc itself doesn't.
 
G

gwowen

It's possible that some header file defines __cdecl and __stdcall as macros, but gcc itself doesn't.

Mingw32 defines __stdcall and __cdecl for compatibility with standard
windows headers.
 
K

Kaz Kylheku

If "void (__cdecl *)()" is a pointer to a function whose calling
convention is cdecl then what are:

void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();

GCC happily accepts all these permutations.

That is false.

$ gcc -x c -
void __cdecl (*)();
void __cdecl (__cdecl *)();
void __cdecl (__stdcall *)();
[Ctrl-D]
<stdin>:1: error: expected declaration specifiers or ‘...’ before ‘*’ token
<stdin>:1: error: ‘__cdecl’ declared as function returning a function
<stdin>:2: error: expected ‘)’ before ‘*’ token
<stdin>:3: error: expected ‘)’ before ‘*’ token

How did you come to the conclusion that it does?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top