karagulamos's Profile
Reputation: 20
Tradesman
- Group:
- Contributors
- Active Posts:
- 17 (0.02 per day)
- Joined:
- 24-November 10
- Profile Views:
- 1,757
- Last Active:
Dec 30 2012 01:07 AM- Currently:
- Offline
Previous Fields
- Country:
- NG
- OS Preference:
- Windows
- Favorite Browser:
- FireFox
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- Playstation
- Your Car:
- Who Cares
- Dream Kudos:
- 175
Latest Visitors
-
CodingSup3rna... 
19 Aug 2012 - 12:00 -
no2pencil 
17 Jun 2012 - 19:10 -
macosxnerd101 
14 Jun 2012 - 14:23 -
ricardosms 
19 May 2012 - 18:49 -
KYA 
19 May 2012 - 09:26 -
newn 
13 Jun 2011 - 03:43 -
ayabrego 
24 Jan 2011 - 23:36 -
xenofied 
17 Dec 2010 - 04:40
Posts I've Made
-
In Topic: do {} while(0);
Posted 12 Aug 2012
sparkart, on 17 August 2011 - 11:14 PM, said:With the do while loop, you can break out of the code on failure:
do { // Failure with return a null(0) value. p = CreateNewObject(); if (p == 0) break; o = CreateDifferentObject(); if (o == 0) break; //... } while(0);
The above method can be avoided. Assuming that the code above is legally correct and the intention is to "do stuff" only when the creation of objects p && o succeeds, then I find the following examples more intuitive:
Example 1
=========
//... p = CreatNewObject(); o = CreateDifferentObject(); if(p != 0 && o != 0){ // true if the creation of p && o succeeded //do stuff ... } // Perhaps some more code and/or cleanup ...
Note that Example 1 incurs the extra cost of creating the object o regardless of whether or not the creation of p succeeded.
Example 2
=========
bool created = false; //... p = CreateNewObject(); if(p != 0){ o = CreateDifferentObject(); if(o != 0) created = true; } if(created){ // true if the creation of p && o succeeded //do stuff ... } // Perhaps some more code and/or cleanup ...
Cheers!
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- July 19
- Gender:
-
- Location:
- Nigeria
- Interests:
- Art, Dance, Drama, Friends, Music and Parapsychology.
- Full Name:
- Alexander Karagulamos
- Years Programming:
- 4
- Programming Languages:
- Assembly, C, C++, Java, VB, Pascal, Python, HTML, CSS, JavaScript, PHP
Contact Information
- E-mail:
- Click here to e-mail me
- Yahoo:
-
karagulamos
- Facebook:
- https://www.facebook.com/karagulamos
Friends
karagulamos hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
karagulamos has no profile comments yet. Why not say hello?