Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #167319
| Path | csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.lang.c |
| Subject | Re: labels at the end of a function |
| Date | Mon, 29 Aug 2022 21:50:54 -0700 |
| Organization | None to speak of |
| Lines | 53 |
| Message-ID | <87edwyibbl.fsf@nosuchdomain.example.com> (permalink) |
| References | <tejphm$19h6e$1@dont-email.me> <af54ed1f-6a3c-4998-8f71-525e150ad9abn@googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | reader01.eternal-september.org; posting-host="412d0bf675f2f96100811070dd3b0ed6"; logging-data="1480542"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+siyF7wcm0M6CbfYp+43t3" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:/XvBecJvIj/f/GSLeG4UPYKNLho= sha1:AlZXfWyL4bbDdN4BUMBcs0iXjCU= |
| Xref | csiph.com comp.lang.c:167319 |
Show key headers only | View raw
Thiago Adams <thiago.adams@gmail.com> writes:
> On Monday, August 29, 2022 at 10:36:05 PM UTC-3, Lynn McGuire wrote:
>> I just found out that a label at the end of a c/c++ function must have
>> an executable statement after it.
>>
>> int aMethod ()
>> {
>> int aFakeVar = 0;
>>
>> goto aLabel;
>>
>> aLabel:
>>
>> aFakeVar++;
>> }
>>
>> Is there any way to get around the requirement of the executable
>> statement after the label ?
>>
>> Thanks,
>> Lynn
>
> aLabel:;
>
> empty ;
One difference between C and C++ is that C++ allows a label to precede a
declaration, but C doesn't. This is a side effect of the way C and C++
express the ability to mix declarations and statements within a block.
In C, a compound-statement contains a list of block-items, where a
block-item is a declaration or a statement (possibly a
labeled-statement). In C++, a compound-statement contains a list of
statements, but a declaration in a block is syntactically a
declaration-statement.
C23 (as of N3047) permits labels anywhere in a block, including on a
declaration and (unlike C++) just before the closing "}". It redefines
a block-item to be any of a declaration, an unlabeled-statement, or a
label.
{
LABEL1: // Invalid in C17, valid in C23 and C++
int n = 42;
LABEL2: // Valid in C and C++
printf("n = %d\n", n);
LABEL3:; // Valid in C and C++
LABEL3: // Valid in C23, invalid in C17 and C++
}
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-29 20:35 -0500
Re: labels at the end of a function Thiago Adams <thiago.adams@gmail.com> - 2022-08-29 18:47 -0700
Re: labels at the end of a function Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-29 21:50 -0700
Re: labels at the end of a function Kaz Kylheku <480-992-1380@kylheku.com> - 2022-08-30 05:52 +0000
Re: labels at the end of a function Sam <sam@email-scan.com> - 2022-08-29 22:42 -0400
Re: labels at the end of a function Anton Shepelev <anton.txt@g{oogle}mail.com> - 2022-08-30 12:46 +0300
Re: labels at the end of a function Juha Nieminen <nospam@thanks.invalid> - 2022-08-30 11:20 +0000
Re: labels at the end of a function Opus <ifonly@youknew.org> - 2022-08-30 20:15 +0200
Re: labels at the end of a function Ike Naar <ike@sdf.org> - 2022-08-30 05:50 +0000
Re: labels at the end of a function Elephant <diespammer@yahoo.it> - 2022-08-30 10:14 +0200
Re: labels at the end of a function Bo Persson <bo@bo-persson.se> - 2022-08-30 09:14 +0200
Re: labels at the end of a function scott@slp53.sl.home (Scott Lurndal) - 2022-08-30 13:21 +0000
Re: labels at the end of a function gazelle@shell.xmission.com (Kenny McCormack) - 2022-08-30 14:44 +0000
Re: labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-30 16:08 -0500
Re: labels at the end of a function Anton Shepelev <anton.txt@gmail.com> - 2022-08-31 01:04 +0300
Re: labels at the end of a function Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-30 20:29 -0500
csiph-web