Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <va76ba$dljb$1@dont-email.me>
Deutsch   English   Français   Italiano  
<va76ba$dljb$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: on allowing "int a" definition everywhere
Date: Thu, 22 Aug 2024 08:10:34 -0300
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <va76ba$dljb$1@dont-email.me>
References: <afdfe7c37c6ad739fd82c7ec0587b82e0963fce2@i2pn2.org>
 <va2i90$3f4dg$1@dont-email.me>
 <pan$8a32c$1fb86219$8ea0c6ae$7c2d1765@invalid.invalid>
 <va4id0$3rc3n$1@dont-email.me>
 <pan$2be2c$5ea44d54$282eec3$b0bcf030@invalid.invalid>
 <va727r$d1jq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 22 Aug 2024 13:10:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="85c23c65ebcc3c54f3fb7aecb1a9f458";
	logging-data="448107"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18eQ4QQDzmbSoQcc+sRa+RMC9BI4+us2bA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:rdD7F6dAsE4NrYhTutbrzcRPVLw=
Content-Language: en-US
In-Reply-To: <va727r$d1jq$1@dont-email.me>
Bytes: 2394

On 22/08/2024 07:00, Bart wrote:
> 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, …);

Yes, this is the equivalent code.

C++ allows two forms. One with explicit check and another one with 
implicit check.


  if (FILE* f = fopen("file.txt", "r"); f) /*f is checked explicitly*/
  {
      /*...*/
      fclose(f);
  }

  if (FILE* f = fopen("file.txt", "r"))  /*f is checked implicitly*/
  {
      /*...*/
      fclose(f);
  }

I also have considered for cake to have a extra part that is "defer" part.

if (FILE* f = fopen("file.txt", "r"); f; fclose(f))
{
}

But if 'defer' were added to C2Y, we could then do the following:

if (FILE* f = fopen("file.txt", "r"); f; )
{
   defer fclose(f);
   /*...*/
}


Sometimes, too much syntactic sugar is not good because it creates too 
many variants.