Deutsch English Français Italiano |
<vspgab$ce6m$3@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Thiago Adams <thiago.adams@gmail.com> Newsgroups: comp.lang.c Subject: Re: do { quit; } else { } Date: Fri, 4 Apr 2025 17:43:55 -0300 Organization: A noiseless patient Spider Lines: 94 Message-ID: <vspgab$ce6m$3@dont-email.me> References: <vspbjh$8dvd$1@dont-email.me> <20250404132935.60@kylheku.com> <20250404133502.695@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 22:43:56 +0200 (CEST) Injection-Info: dont-email.me; posting-host="26bb03f5d8244956539c851a3efacaaf"; logging-data="407766"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nHDHGTH2zCNgC5pqo+pkg4mrvWKoEvKY=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:CsNP4HHf+q/gtuqjSy1TqYtx7Mg= In-Reply-To: <20250404133502.695@kylheku.com> Content-Language: en-GB Bytes: 2871 Em 4/4/2025 5:39 PM, Kaz Kylheku escreveu: > On 2025-04-04, Kaz Kylheku <643-408-1753@kylheku.com> wrote: >> On 2025-04-04, Thiago Adams <thiago.adams@gmail.com> wrote: >>> What do you think of this control block? >>> >>> do >>> { >>> FILE f = fopen("file.txt", "r"); >>> >>> if (f == NULL) quit; /*goes to else part*/ >>> >>> /*success here*/ >>> for (int i =0; i < 10; i++){ >>> ... >>> if (error) quit; >>> } >>> >>> } >>> else >>> { >>> /*some error*/ >>> } >> >> >> 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); >> ... >> } >> >> If you make that work, you're creating scope wormholes between >> disjoint curly braces, which is not allowed if youre name isn't >> Bjarne Stroustrup. > > How about: do/else if/else if/else with argument passing to first > clause whose signature can take the argument list: > > do { > ... > quit("rage"); // goes to (char *arg) > ... > quit(42); // goes to (int arg) > ... > } > else if (char *arg) // or just else? multiple elses on do, why not. > { > } > else (int arg) > { > } > > Friday `f`noons, eh? > In this case.. I think try throw catch is suitable. try{ throw 1; } catch (int e){ } try{ throw; } catch { } but...the pattern I use is.. { int error = 0; try{ error = ... if (error != 0) throw; } catch { } return error; }