From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: Ralph Corderoy Message-ID: <3afa.3e16dd11.67d1a@blake.inputplus.co.uk> References: <38aa463bafe23035decff6b0364f7553@plan9.bell-labs.com>, <20021119103808.B13548@unicorn.math.spbu.ru> Subject: Re: [9fans] how to avoid a memset() optimization Date: Mon, 6 Jan 2003 10:18:19 +0000 Topicbox-Message-UUID: 3bae455c-eacb-11e9-9e20-41e7f4b1d025 Hi Roman, > Of course, good old: > > if ((a = do_it()) == BadThingHappened) > return TellEmAboutIt; > > works, but costs a little bit too much when clarity is needed. > Especially when a "transaction" like pattern is needed ( e.g. I need > to to have o1 = f1(); o2 = f2(); o3 = f3(); but if any of f* fails, I > have to destroy what I've got so far ). A common way of doing this is using goto. failed = 1; if ((res1 = lock(A) == 0) { goto releaseA; } if ((res2 = lock(B) == 0) { goto releaseB; } if ((res3 = lock(C) == 0) { goto releaseC; } foo(res1, res2, res3); failed = 0; releaseC: release(C); releaseB: release(B); releaseA: release(A); return failed; Cheers, -- Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/