Click here to Skip to main content
15,913,159 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: OpenGL or DirectX ? Pin
Mike Nordell9-Feb-03 15:03
Mike Nordell9-Feb-03 15:03 
GeneralQuestion about printf("%ld", ...) Pin
George29-Feb-03 1:05
George29-Feb-03 1:05 
GeneralRe: Question about printf("%ld", ...) Pin
Tim Smith9-Feb-03 1:25
Tim Smith9-Feb-03 1:25 
GeneralRe: Question about printf("%ld", ...) Pin
George29-Feb-03 1:35
George29-Feb-03 1:35 
GeneralRe: Question about printf("%ld", ...) Pin
Gary R. Wheeler9-Feb-03 5:00
Gary R. Wheeler9-Feb-03 5:00 
GeneralRe: Question about printf("%ld", ...) Pin
Nitron9-Feb-03 9:49
Nitron9-Feb-03 9:49 
GeneralRe: Question about printf("%ld", ...) Pin
Gary R. Wheeler9-Feb-03 11:34
Gary R. Wheeler9-Feb-03 11:34 
GeneralQuestion about const int& Pin
George28-Feb-03 23:30
George28-Feb-03 23:30 
GeneralRe: Question about const int& Pin
Stephane Rodriguez.8-Feb-03 23:45
Stephane Rodriguez.8-Feb-03 23:45 
GeneralRe: Question about const int& Pin
George28-Feb-03 23:49
George28-Feb-03 23:49 
GeneralRe: Question about const int& Pin
Stephane Rodriguez.9-Feb-03 0:13
Stephane Rodriguez.9-Feb-03 0:13 
GeneralRe: Question about const int& Pin
George29-Feb-03 0:33
George29-Feb-03 0:33 
GeneralRe: Question about const int& Pin
Stephane Rodriguez.9-Feb-03 0:47
Stephane Rodriguez.9-Feb-03 0:47 
GeneralRe: Question about const int& Pin
George29-Feb-03 0:58
George29-Feb-03 0:58 
GeneralRe: Question about const int& Pin
includeh109-Feb-03 0:38
includeh109-Feb-03 0:38 
GeneralRe: Question about const int& Pin
George29-Feb-03 0:41
George29-Feb-03 0:41 
GeneralRe: Question about const int& Pin
Gary R. Wheeler9-Feb-03 5:06
Gary R. Wheeler9-Feb-03 5:06 
GeneralRe: Question about const int& Pin
Jambolo9-Feb-03 22:39
Jambolo9-Feb-03 22:39 
Ahhh, the beauty of const & parameters! I use these two conventions:

1. If a parameter is passed as a reference, it must always be a const reference.

In the following code, does foo change the value of bar or not?
foo( bar );

Most people would say no, but foo could be defined like this:
void foo( int & x ) { ++x; }

Since people are suprised when something like that happens, it is a source of bugs, so it is a bad idea. Don't change the value of parameters passed by reference. And since the reference is never going to change, you might as well make it const.

If the code looks like this...
foo( &bar );

...then people are not be surpised if the value of bar is changed by foo. So, if the value is changed, use *, If it isn't, use const &.

2. Prefer const & to const *.

So, why use const & when you can use const *? There are other reasons, but here is mine: A function call that doesn't change the value of a parameter should look like it doesn't change the value and vice versa.
void foo( int const & x ) { ... } // Neither of these ...
void foo( int const * x ) { ... } // ... functions change x (or *x)
...
foo( bar );    // This call does not appear to change bar
foo( &bar );   // This call appears that it could change bar
               // but it doesn't

GeneralESC closing dialog Pin
S O S8-Feb-03 23:18
S O S8-Feb-03 23:18 
GeneralRe: ESC closing dialog Pin
skaanji9-Feb-03 0:47
skaanji9-Feb-03 0:47 
GeneralRe: ESC closing dialog Pin
S O S9-Feb-03 3:22
S O S9-Feb-03 3:22 
GeneralDirectX HELP!!! Pin
Ehsan Baghaki8-Feb-03 22:15
Ehsan Baghaki8-Feb-03 22:15 
GeneralRe: DirectX HELP!!! Pin
Anonymous8-Feb-03 23:03
Anonymous8-Feb-03 23:03 
QuestionWhat means cout.precision (4)? Pin
George28-Feb-03 22:09
George28-Feb-03 22:09 
AnswerRe: What means cout.precision (4)? Pin
Mike Nordell9-Feb-03 2:07
Mike Nordell9-Feb-03 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.