Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" Newsgroups: comp.lang.c Subject: Re: do { quit; } else { } Date: Fri, 4 Apr 2025 14:36:32 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: <20250404132935.60@kylheku.com> <20250404140041.532@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 04 Apr 2025 23:36:33 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e2c747021cf4b98cdbf0e00a9e01b7cd"; logging-data="540908"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DtHAqxTkW2+GMtTNpD6cGW8VH4rIlDb4=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:19Kvb2yjTF1d5VU9Cyrhd7omSyE= Content-Language: en-US In-Reply-To: <20250404140041.532@kylheku.com> Bytes: 1856 On 4/4/2025 2:01 PM, Kaz Kylheku wrote: > On 2025-04-04, Thiago Adams wrote: >> Em 4/4/2025 5:34 PM, Kaz Kylheku escreveu: >>> The else part might need access to some local variables >>> in the main part. >>> >>> do { >>> char *name = calculate_path(PATH_PREFIX "/", name, ".txt"); >>> FILE *f = fopen(...) >>> >>> if (!f) >>> quit; >>> ... >>> } >>> else >>> { >>> printf("unable to open %s\n", name); >>> ... >>> } >> >> In this case we move the scope of the variable we need. > > Your name isn't Bjarne Stroustrup, so you're not allowed to > create scope wormholes between disjoint curly braces. > Shit happens... ;^)