Deutsch English Français Italiano |
<pan$2be2c$5ea44d54$282eec3$b0bcf030@invalid.invalid> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail From: Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> Newsgroups: comp.lang.c Subject: Re: on allowing "int a" definition everywhere Date: Thu, 22 Aug 2024 08:40:30 -0000 (UTC) Organization: A noiseless patient Spider Lines: 57 Message-ID: <pan$2be2c$5ea44d54$282eec3$b0bcf030@invalid.invalid> References: <afdfe7c37c6ad739fd82c7ec0587b82e0963fce2@i2pn2.org> <va2i90$3f4dg$1@dont-email.me> <pan$8a32c$1fb86219$8ea0c6ae$7c2d1765@invalid.invalid> <va4id0$3rc3n$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 22 Aug 2024 10:40:30 +0200 (CEST) Injection-Info: bluemanedhawk.eternal-september.org; posting-host="2dd037933cadca52db881fdd9e2bdd9e"; logging-data="405927"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BxAmc9UKdDLCgh3ANiMhWfeuKyqLF8nI=" User-Agent: Pan/0.154 (Izium; 517acf4) Cancel-Lock: sha1:m1mbSTOqbslC+WnlRYj1mWAnKcI= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9 jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq 0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1 z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9 R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6 k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx 2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII= X-Face: Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronuku pokaiwhenuakitanatahu Bytes: 3787 Thiago Adams wrote: > On 21/08/2024 01:42, Blue-Maned_Hawk wrote: >> Thiago Adams wrote: >> >>> initializer inside if is already in C++, and it will probably be on >>> C2Y. >> If it's for consistency with how for loops permit declarations, i would >> _much_ prefer that they just outlaw that to induce consistency. >> >> (Really, i'd ideally want things to just stay as they are, since >> declarations in for loops are simply too useful for macros.) > > I like the ability to declare things inside if. > > if (FILE* f = fopen("file.txt", "r")) > { > /*...*/ fclose(f); > } > > Because it makes the scope of f, associated with the pointed object > lifetime. > > For instance, if you try to use f > > if (FILE* f = fopen("file.txt", "r")) > { > /*...*/ fclose(f); > } > fwrite(f, ..) ;// ERROR You can already do that in C23: if (…) { FILE * f = fopen("file.txt", "r"); /* … */ fclose(f); } fwrite(f, …); /* Some kind of error happens. */ Or, if you need it to exist before the controlling expression: for (bool x = true; x; x = false) for (FILE * f = fopen("file.txt", "r"); x; x = false) if (…) { /* … */ fclose(f); } fwrite(f, …); Therefore, your example does not work as evidence in favor of declarations in if statement controlling expressions because it's already possible in other ways. -- Blue-Maned_Hawk│shortens to Hawk│/blu.mɛin.dʰak/│he/him/his/himself/Mr. blue-maned_hawk.srht.site Banned in the UK for several years!