Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > Jump to label

Reply
Thread Tools Display Modes

Jump to label

 
 
Kid
Guest
Posts: n/a

 
      05-23-2008
Hi

I've seen many driver source use goto error label in functions .

Is it a good way to write driver functions ? I seldom found goto label in
application
project source .

Thank you.
 
Reply With Quote
 
 
 
 
Doron Holan [MSFT]
Guest
Posts: n/a

 
      05-23-2008
it is all a matter of style. typically you see one of three options
1) alot of nested if()s which check for success
2) a flat strucure of if()s, on failure goto error;
3) a do { } while (FALSE) loop. on error, you see a break; this is the
same as #2

it really just dpeends on what you want to maintain...

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Kid" <> wrote in message
news:771ACB4A-2D5C-4699-AEB4-...
> Hi
>
> I've seen many driver source use goto error label in functions .
>
> Is it a good way to write driver functions ? I seldom found goto label
> in
> application
> project source .
>
> Thank you.


 
Reply With Quote
 
Ray Trent
Guest
Posts: n/a

 
      05-23-2008
Doron Holan [MSFT] wrote:
> it is all a matter of style. typically you see one of three options
> 1) alot of nested if()s which check for success
> 2) a flat strucure of if()s, on failure goto error;
> 3) a do { } while (FALSE) loop. on error, you see a break; this is the
> same as #2


Or, in C++ (hehe), using the "resource allocation is initialization"
(RAII) paradigm to clean up from error conditions (or any other exit
from a block) automatically in a destructor. Kind of a pain to write in
the general case, but it does make maintaining the code a lot less
hazardous for junior programmers.

Lots of nested if's tend to make my head hurt, especially when it's time
to maintain the code. So to me this is one of the rare circumstances
where goto's actually make a lot of sense.

I don't much like the do while false trick because it leaves you stuck
in lots of situations like this:

do {
for(...) {
success = DoSomething();
if (!success) {
?????????
}
}
} while(FALSE);

It's especially pernicious when this happens accidentally because
another programmer came along and added the for loop.

Yes, you can get around that by having a error holding stack variable
that is checked after any nested loops, but ugh.
--
Ray
 
Reply With Quote
 
Egidio [MSFT]
Guest
Posts: n/a

 
      05-23-2008
Plus applications often use try/catch/finally to be 'more' object oriented.

Egi.

"Doron Holan [MSFT]" <> wrote in message
news:...
> it is all a matter of style. typically you see one of three options
> 1) alot of nested if()s which check for success
> 2) a flat strucure of if()s, on failure goto error;
> 3) a do { } while (FALSE) loop. on error, you see a break; this is the
> same as #2
>
> it really just dpeends on what you want to maintain...
>
> d
>
> --
> Please do not send e-mail directly to this alias. this alias is for
> newsgroup purposes only.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
> "Kid" <> wrote in message
> news:771ACB4A-2D5C-4699-AEB4-...
>> Hi
>>
>> I've seen many driver source use goto error label in functions .
>>
>> Is it a good way to write driver functions ? I seldom found goto label
>> in
>> application
>> project source .
>>
>> Thank you.

>



 
Reply With Quote
 
440gtx@email.com
Guest
Posts: n/a

 
      05-24-2008
Indeed. Just the small step of using auto_ptr is a more beautiful and
safe way to clean up rather rather than goto spaghetti.
 
Reply With Quote
 
Doron Holan [MSFT]
Guest
Posts: n/a

 
      05-27-2008
note that would be the SEH versions of try/catch/finally not the c++
versions, at least for drivers...which really means __try and __finally
w/out the throw. also note that code in a __try block will likely not be
optimized b/c the compiler has a very hard time knowing what will raise an
exception or not

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Egidio [MSFT]" <> wrote in message
news:%...
> Plus applications often use try/catch/finally to be 'more' object
> oriented.
>
> Egi.
>
> "Doron Holan [MSFT]" <> wrote in message
> news:...
>> it is all a matter of style. typically you see one of three options
>> 1) alot of nested if()s which check for success
>> 2) a flat strucure of if()s, on failure goto error;
>> 3) a do { } while (FALSE) loop. on error, you see a break; this is the
>> same as #2
>>
>> it really just dpeends on what you want to maintain...
>>
>> d
>>
>> --
>> Please do not send e-mail directly to this alias. this alias is for
>> newsgroup purposes only.
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>> "Kid" <> wrote in message
>> news:771ACB4A-2D5C-4699-AEB4-...
>>> Hi
>>>
>>> I've seen many driver source use goto error label in functions .
>>>
>>> Is it a good way to write driver functions ? I seldom found goto label
>>> in
>>> application
>>> project source .
>>>
>>> Thank you.

>>

>
>


 
Reply With Quote
 
440gtx@email.com
Guest
Posts: n/a

 
      05-28-2008
> also note that code in a __try block will likely*not be
> optimized b/c the compiler has a very hard time knowing
> what will raise an exception or not


The compiler will know exactly what, if any exception will be raised
if throw() is specified in the function prototype. But you can only
use the magical throw() if your driver is C++ rather than C.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Icon Label Placement Lonewolf Windows Vista General Discussion 1 03-13-2008 01:50 AM
Booting Vista on Different PC Computers No label cccharlee@inbox.com Windows Vista General Discussion 5 01-16-2008 05:28 PM
psc 1210 all in one printer - Label Problem Bill Windows Vista Printing / Faxing / Scanning 6 10-12-2007 09:28 PM
License label Tony Windows Vista General Discussion 1 07-06-2007 05:00 AM
How to label files by color in Explorer.... Jeff Ingram Windows Vista General Discussion 2 03-16-2007 08:39 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59