RE: RE: Re: [BULK] Re: Modern C++ Features in Kernel Mode Drivers

Well, once you were repeatedly speaking about “dumb people who cannot see the advantages of C++” all over the place on this thread, I am going to beat you with your own argument, and say that “some people are just too dumb to see the advantages that goto statement offers”.

In actuality, it may be really useful in a situation when you have to do multi-stage cleanup, and the particular stage at which you have to start your cleanup depends on whether you had earlier failed, and if you did, at which particular stage this failure had occurred. For example consider the following code:

status=stage0(args…);
if(status) goto done;

status=stage1(args…);
if(status) goto failure1;

status=stage2(args…);
if(status) goto failure2;

status=stage3(args…);
if(status) goto failure3;

do_things();
stage3_cleanup(args…);

failure3: stage2_cleanup(args…);
failure2: stage1_cleanup(args…);
failure1: stage0_cleanup(args…).;
done: return status;

Now compare it to do-while() loop approach that you can see in WDK samples,with cleanup taking place immediately after the failure and being followed with break statement. Which of them do you think is easier to read and maintain???

Surely you can use goto statement for writing spaghetti code that would,probably, qualify for the code obfuscation contest, but this is already the question of a programmer, rather than that of a language construct that (s)he misuses…

Anton Bassov