tags:

views:

87

answers:

2

Why can WinMain have two return types?

If I remove it,will report this warning:

warning C4007: 'WinMain' : must be '__stdcall'

Or I'm reading int WINAPI wrongly?

UPDATE

I tried these two variants which are said to be the same as WINAPI,none work:

int __declspec WinMain

int __declspec(stdcall) WinMain 
+3  A: 

WINAPI isn't a return type it's a macro expanding to an implementation specific decoration or attribute for the function. In this instance it specifies the calling convention and is equivalent to __stdcall .

Grammatically, WINAPI is roughly (but not exactly) equivalent to a storage class specifier like static.

Charles Bailey
But what does `__declspec(stdcall)` mean then? The regular form should be: `[return type] function_name(parameters)`,right?
@user198729: http://en.wikipedia.org/wiki/Calling_convention . And yes, normally it should just be `returnType func(parameters)`, but `__declspec` is a Microsoft extension.
jamesdlin
@user198729: That's the simplest form of function declaration. The function could also be declared `static` or `inline` which affects the meaning of the function declaration but not the return type. `WINAPI` is a windows specific extension that specifies the calling convention but doesn't otherwise change the meaning of the function declaration.
Charles Bailey
@jamesdlin , do you mean that calling convention only exists for windows?
My fault, It's `__stdcall`, not __declspec(stdcall); it's meaning is what I originally stated, though.
Charles Bailey
All platforms have a calling convention. Some have ways of choosing a specific calling convention (like windows); others only support a single calling convention so it's never mentioned or specified in code.
Charles Bailey
+1  A: 

WINAPI is not a second return value, but a #define for __stdcall.

__stdcall is a calling convention, that handles amongst others how the parameters are given to the function.

DerKuchen
So `__stdcall` is the same as `__declspec(stdcall)` mentioned by @Charles Bailey,right?
I think it is, though I only know it in the `__stdcall` form, that is used in <WinDef.h>
DerKuchen
Sorry, __stdcall is correct. I just had a braino.
Charles Bailey
Does this kinda stuff only exists in windows?
`WINAPI` and `__stdcall` are Microsoft specific but other platforms can and do have their own extensions for using something other than the standard calling convention.
Charles Bailey