By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,442 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,442 IT Pros & Developers. It's quick & easy.

equivalent of __leave in linux

P: 18
Can any one tell me how to implement '__leave' functionality in g++ compiler???Thanx in advance
May 29 '07 #1
Share this Question
Share on Google+
3 Replies


P: 16
i'm not familiar with _leave, what does it do?
May 29 '07 #2

P: 18
i'm not familiar with _leave, what does it do?
It acts like a 'break' statement for try block..You leave the block under some condition.

eg:

__try{
if (a==0) __leave;
b=c;
}
__finally{
printf("something");
}

Here if (a==0) condition fails it will directly come to __finally and prints...

I cannot use break here since it is used for either switch or for loop...
So I want some equivalent...I don't wanna use 'goto' here...Some alternative suggestion for g++ compiler is appreciable since __leave will not work for g++
May 29 '07 #3

AdrianH
Expert 100+
P: 1,251
It acts like a 'break' statement for try block..You leave the block under some condition.

eg:

__try{
if (a==0) __leave;
b=c;
}
__finally{
printf("something");
}

Here if (a==0) condition fails it will directly come to __finally and prints...

I cannot use break here since it is used for either switch or for loop...
So I want some equivalent...I don't wanna use 'goto' here...Some alternative suggestion for g++ compiler is appreciable since __leave will not work for g++
How about:
Expand|Select|Wrap|Line Numbers
  1. __try{
  2.   if (a!=0) {
  3.     b=c;
  4.   }
  5. }
  6. __finally{
  7.   printf("something");
  8. }
I dislike the use of break (except in the use of switch/case, as it is required in that case, but that structure should only be used if it has value), continue, goto and equivilant code as they make reading the flow more difficult by making multiple entry and restart points. It also makes the code harder to prove correct.

try/catch is an exception ('scuse the pun), as it is doing a specific seperation of normal code flow with exceptional code flow.

I also recommend the use of using braces for code blocks as it can make the intent clearer and reduces the number of avoidable errors.

Is there a reason why you are using MS SEH? Becareful if you use it along side of C++'s exception handling, I don't think that they play nice together.


Adrian
May 29 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.