Click here to Skip to main content
15,886,963 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: For loop Pin
Victor Nijegorodov25-Sep-23 5:32
Victor Nijegorodov25-Sep-23 5:32 
GeneralRe: For loop Pin
Calin Negru25-Sep-23 5:42
Calin Negru25-Sep-23 5:42 
AnswerRe: For loop Pin
Randor 25-Sep-23 5:36
professional Randor 25-Sep-23 5:36 
GeneralRe: For loop Pin
jschell25-Sep-23 7:25
jschell25-Sep-23 7:25 
QuestionRe: For loop Pin
Randor 25-Sep-23 7:48
professional Randor 25-Sep-23 7:48 
AnswerRe: For loop Pin
jschell26-Sep-23 5:10
jschell26-Sep-23 5:10 
GeneralRe: For loop Pin
Randor 26-Sep-23 5:38
professional Randor 26-Sep-23 5:38 
GeneralRe: For loop Pin
jschell27-Sep-23 5:23
jschell27-Sep-23 5:23 
Randor wrote:
6.2.4 Storage durations of objects


But 6.2.4 says nothing about how a stack frame is built.

Just as with your other reference it explains what the compiler must enforce but not how it must enforce it.

Following is the only thing that relates to the language

4 An object whose identifier is declared with no linkage and without the storage-class specifier statich asautomatic storage duration. 

5 For such an object that does not have a variable length array type, its lifetime extends from entry into the block with which it is associated until execution of that block ends in anyway.(Entering an enclosed block or calling a function suspends, but does not end, execution of the current block.) If the block is entered recursively, a new instance of the object is created each time. The initial value of the object is indeterminate. If an initialization is specified for the object, it is performed each time the declaration is reached in the execution of the block; otherwise, the value becomes indeterminate each time the declaration is reached.


The second paragraph is the only one even close to relevant and basically makes the same point as your other reference.

It does not specify how it is built on the stack frame.

Again a compiler writer could make a fully compliant compiler which used new slots on the stack frame for each block. Or it could reuse existing ones. Both implementations are compliant.

The referenced section allows a compiler writer to produce optimized code that reuses the slots. And they cannot be considered non-compliant if someone attempts to use a declared variable in a block outside the block (for example via a pointer.)

Consider exactly that case - using a pointer outside the block.
1. Compiler A uses new slots so the code works.
2. Compiler B reuses slots so the code doesn't work.

The user complains that Compiler B is non-compliant. The creators can tell them explicitly that they are using code that the spec does not support.

But it says nothing about Compiler A. Compiler A is NOT required to attempt to determine that a pointer belongs to a variable that goes out of scope. (Similar to having a method return a pointer to a local variable.) The compiler might choose to warn about that but is not required to do so.
JokeRe: For loop Pin
Randor 27-Sep-23 6:57
professional Randor 27-Sep-23 6:57 
GeneralRe: For loop Pin
trønderen28-Sep-23 13:50
trønderen28-Sep-23 13:50 
GeneralRe: For loop Pin
jschell29-Sep-23 11:07
jschell29-Sep-23 11:07 
GeneralRe: For loop Pin
trønderen29-Sep-23 11:35
trønderen29-Sep-23 11:35 
GeneralRe: For loop Pin
Randor 29-Sep-23 12:04
professional Randor 29-Sep-23 12:04 
GeneralRe: For loop Pin
jschell2-Oct-23 5:09
jschell2-Oct-23 5:09 
GeneralRe: For loop Pin
Randor 2-Oct-23 5:47
professional Randor 2-Oct-23 5:47 
GeneralRe: For loop Pin
trønderen2-Oct-23 8:01
trønderen2-Oct-23 8:01 
GeneralRe: For loop Pin
Randor 2-Oct-23 8:27
professional Randor 2-Oct-23 8:27 
GeneralRe: For loop Pin
trønderen2-Oct-23 12:17
trønderen2-Oct-23 12:17 
GeneralRe: For loop Pin
Randor 2-Oct-23 12:54
professional Randor 2-Oct-23 12:54 
GeneralRe: For loop Pin
trønderen2-Oct-23 21:11
trønderen2-Oct-23 21:11 
GeneralRe: For loop Pin
Randor 3-Oct-23 0:08
professional Randor 3-Oct-23 0:08 
GeneralRe: For loop Pin
trønderen3-Oct-23 9:54
trønderen3-Oct-23 9:54 
GeneralRe: For loop Pin
jschell3-Oct-23 4:35
jschell3-Oct-23 4:35 
GeneralRe: For loop Pin
k505429-Sep-23 11:55
mvek505429-Sep-23 11:55 
GeneralRe: For loop Pin
Randor 29-Sep-23 12:14
professional Randor 29-Sep-23 12:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.