<div dir="ltr"><div>Yes, exactly... declarations must be at top of scope in C, while C++ (seen from a C perspective) inserts an implied do { ... } while (0); around the actual scope of stray declarations. Thanks for clarifying that: My brain is so C style hardwired that I didn&#39;t consider the case of declaring things anywhere else than at top of scope.<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-04-24 12:05 GMT+02:00 Mateusz Loskot <span dir="ltr">&lt;<a href="mailto:mateusz@loskot.net" target="_blank">mateusz@loskot.net</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 24 April 2018 at 11:45, Thomas Knudsen &lt;<a href="mailto:knudsen.thomas@gmail.com">knudsen.thomas@gmail.com</a>&gt; wrote:<br>
&gt;&gt; In C too, but since C99.<br>
&gt;<br>
&gt; AFAIK this only applies to the &quot;for (int i = 0;  i &lt; n; i++)&quot; syntax.<br>
&gt;<br>
&gt; while (...) {<br>
&gt;     int i = 123, j = 345;<br>
&gt;     k = i + j;<br>
&gt; }<br>
&gt;<br>
&gt; has been correct (and imho, preferable) syntax since K&amp;R C<br>
<br>
</span>AFAIK, it&#39;s about compound statement.<br>
C89 requires declaration at the top of blocks, while C99 lifts that:<br>
<br>
$ cat test.c<br>
int main()<br>
{<br>
    int i = 0;<br>
    while (i &lt; 10)<br>
    {<br>
        int j = 345;<br>
        i = i + j;<br>
    }<br>
<br>
    {<br>
        int z = 0;<br>
        z = 1;<br>
    }<br>
    int x = 1;<br>
}<br>
<br>
$ gcc -std=c89 -pedantic test.c<br>
test.c: In function ‘main’:<br>
test.c:14:5: warning: ISO C90 forbids mixed declarations and code<br>
[-Wdeclaration-after-<wbr>statement]<br>
     int x = 1;<br>
     ^~~<br>
<br>
$ gcc -std=c99 -pedantic test.c<br>
$<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Best regards,<br>
-- <br>
Mateusz Loskot, <a href="http://mateusz.loskot.net" rel="noreferrer" target="_blank">http://mateusz.loskot.net</a><br>
______________________________<wbr>_________________<br>
Proj mailing list<br>
<a href="mailto:Proj@lists.maptools.org">Proj@lists.maptools.org</a><br>
<a href="http://lists.maptools.org/mailman/listinfo/proj" rel="noreferrer" target="_blank">http://lists.maptools.org/<wbr>mailman/listinfo/proj</a></div></div></blockquote></div><br></div>