c - Is it valid to initiate the size part of a VLA in the same sequencepoint as the VLA is declared? -


in post: https://stackoverflow.com/questions/38326930/cannot-read-full-100000-integer-values-from-a-file-in-c

the op contains code there lot wrong with, 1 line made me curios, since wasn't able up, disallowing it.

this specific line:

int n = 100000, arr[n]; 

is order of declaration , initialization beeing ensured?

so here assume might happen n wasn't initialized when arr gets declared, obvisiously not good.

but wasn't able find statement regarding in iso/iec 9899 draft @ hand neither stating undefined nor defining it.

so assume not defined behavior? or it?

and either way, rule beeing applyed result?5

edit:

is valid c99, too?

in short: code correct. premise wrong. 2 declarations not "in same sequence point". (as sidenote: there cannot in point, between 2 points, points dimensionless).

the details:

6.8.2 of standard shows grammar of compound statement basis of every function body:

compound-statement:     { block-item-listopt } block-item-list:     block-item     block-item-list block-item block-item:     declaration     statement 

relevant here block-item. shown, can statement or declaration. implies declaration not statement. show declaration, , not operator here, seperates init-declarators (a declarator optionally initialiser, see 6.7 grammar). , there sequence point right after declarator (and before optional initialiser, btw.).

6.7.6p3: full declarator declarator not part of declarator. the end of full declarator sequence point. if, in nested sequence of declarators in full declarator, there declarator specifying variable length array type, type specified full declarator said variably modified. furthermore, type derived declarator type derivation variably modified type variably modified.

regarding "execution order": left implementation. standard requires follow abstract machine. sequence points fundamental ordering concept.


the question not directly related vlas, declarators in general. without citing sections of previous versions, behaviour identical in version, because otherwise int = 3, k = i; not work (it does).


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -