Liste des Groupes | Revenir à cl c |
On 22/08/2024 09:40, Blue-Maned_Hawk wrote:btw maybe not so much relevent as what you write butThiago 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 onIf it's for consistency with how for loops permit declarations, i would
C2Y.
_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, …);
>
I wonder, if I laid it out it properly:
>
for (bool x = true; x; x = false)
for (FILE * f = fopen("file.txt", "r"); x; x = false)
if (…) {
/* … */
fclose(f);
}
fwrite(f, …);
>
Nope; I still haven't the faintest idea what this is supposed to do. I
suspect that it doesn't actually run or need those two nested loops.
>
I assume the (...) tests the value of 'f'? If so then perhaps this is a
shorter way of expressing the same thing:
>
{
FILE * f = fopen("file.txt", "r");
if (f) {
/* … */
fclose(f);
}
}
fwrite(f, …);
>
Les messages affichés proviennent d'usenet.