<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'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"><<a href="mailto:mateusz@loskot.net" target="_blank">mateusz@loskot.net</a>></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 <<a href="mailto:knudsen.thomas@gmail.com">knudsen.thomas@gmail.com</a>> wrote:<br>
>> In C too, but since C99.<br>
><br>
> AFAIK this only applies to the "for (int i = 0; i < n; i++)" syntax.<br>
><br>
> while (...) {<br>
> int i = 123, j = 345;<br>
> k = i + j;<br>
> }<br>
><br>
> has been correct (and imho, preferable) syntax since K&R C<br>
<br>
</span>AFAIK, it'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 < 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>