Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 27th, 2005, 10:16 PM   #31
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by DaWei
++i, with i as an integer, is no more (and no less) efficient than i++. The preincrement operator may be more efficient when applied to an object, depending strictly upon the characteristics of the object. It's one of those issues that people speak strongly about because they heard it somewhere, and that's good enough for them.
I read it a while back in Practical C Programming by Steve Oualline... (Yes I said Practical C, not C++) Here it is:

Quote:
Originally Posted by Practical C Programming (Chapter 5, page 80-81, third edition)
++x or x++
The two forms of the increment operator are called the prefix form (++x) and the postfix form (x++). Which form should you use? Actually in C your choice doesn't matter. However, if you use C++ with its overloadable operators, the prefix version (++x) is more efficient.* So, to develop good habits for learning C++, use the prefix form.*

* For details, see the book Practical C++ Programming (O'Reilly & Associates).
*Consider the irony of a language with its name in postfix form (C++) working more efficiently with prefix forms of the increment and decrement operators. Maybe the name should be ++C.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 28th, 2005, 8:30 AM   #32
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
That's essentially the point made in the thread -- incrementing atomic thangys versus objects (overloading) and imbuing atomic incrementation order with an importance it doesn't have because of the differences possible for non-atomic types. Am I missing another point in your post?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 28th, 2005, 2:28 PM   #33
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by DaWei
That's essentially the point made in the thread -- incrementing atomic thangys versus objects (overloading) and imbuing atomic incrementation order with an importance it doesn't have because of the differences possible for non-atomic types. Am I missing another point in your post?
Not at all. I'm just telling you where I heard it from.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline   Reply With Quote
Old Nov 28th, 2005, 4:07 PM   #34
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
However, if you use C++ with its overloadable operators, the prefix version (++x) is more efficient.*
Depends on what you "hear" when you read that, I guess.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC