Is the C ++ conditional convention a limited standard, since the return type of a function does not have to be defined when declaring fn?

Studying the definition rule 1 on Wikipedia, I was stuck with the following example in the Examples section:

struct S;     // declaration of S
...
S f();        // ok, no definition required
...

I know that stack space should be allocated for the return value, but when I saw this example, I thought that C ++ calling conventions might indicate that the stack control for the return value is handled by a block of code in which this function not the block of code in which it is called. Therefore, I examined the “C and C ++ calling convention” (recall that the problem of allocating stack return values ​​may be the main difference), and came across this answer , which indicates that the “calling convention” is not defined by the standard.

However, given the obvious requirement that the above code snippet is valid, it seems to me that there should be some restrictions when invoking an agreement to support the above code snippet.

I'm right? Is the C ++ standard an implicit requirement that stack control for the return value of a function be handled by code defining the function to support the syntax above?

+4
source share
2 answers

As mentioned in the comments

As you wrote your example, Both Struct S and function f are forward declarations. The compiler will really complain if you try to use either

** EDIT, as Stephen Surit noted, function f is not a forward declaration, but a prototype of a function **

and

, , ( ) , . ++ " ". 7.5

? ++ , , , ?

, , / (FASTCALL) Microsoftsoft (thiscall), .

+4

C/++ . , , , , , .

C/++ ( , ..), , - ( , , , ..).

x86 __cdecl __stdcall ( __cdecl), (Microsoft __fastcall/__thiscall, Borland __fastcall/__safecall/__msfastcall ..).

x64 , x64. x64, ( / ).

+2

Source: https://habr.com/ru/post/1544417/


All Articles