Click here to Skip to main content
15,884,237 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralPassing by reference vs. Value Pin
LCI11-Apr-08 4:20
LCI11-Apr-08 4:20 
GeneralRe: Passing by reference vs. Value Pin
led mike11-Apr-08 4:28
led mike11-Apr-08 4:28 
GeneralRe: Passing by reference vs. Value Pin
LCI11-Apr-08 4:40
LCI11-Apr-08 4:40 
GeneralRe: Passing by reference vs. Value Pin
CPallini11-Apr-08 4:46
mveCPallini11-Apr-08 4:46 
GeneralRe: Passing by reference vs. Value Pin
Cedric Moonen11-Apr-08 4:47
Cedric Moonen11-Apr-08 4:47 
GeneralRe: Passing by reference vs. Value Pin
led mike11-Apr-08 6:14
led mike11-Apr-08 6:14 
GeneralRe: Passing by reference vs. Value Pin
CPallini11-Apr-08 4:32
mveCPallini11-Apr-08 4:32 
AnswerRe: Passing by reference vs. Value Pin
Bram van Kampen11-Apr-08 12:21
Bram van Kampen11-Apr-08 12:21 
Hi
There is much confusion, in particular amongst novices, about Pointers, References snd Values when used as arguments.

Using a Value is clear, a copy of the value gets placed on the stack. You can do what you want with it, it will be lost when the stack is cut down when you return from the procedure.

A pointer is also clear, You're passing on the address of some data. That data resides elsewhere, but you're given the access to the original. so Changing the data through the pointer affects the original.

The problem here is that the Pointer may not point at valid memory. This is a condition that can only be checked at runtime. There is no way the compiler can use to check the validity of a pointer at Compile Time.

When you use a Reference, you will get passed the address of the variable to your procedure, and the generated code is identical to passing a pointer. The difference is, that unlike passing pointers, the language syntax and semantics force you to enter the correct variable name.

Hope this helps. Smile | :)

Bram van Kampen

GeneralCompiling a Parser Generator generated file causes linker errors Pin
Manfr3d11-Apr-08 4:11
Manfr3d11-Apr-08 4:11 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
rp_suman11-Apr-08 4:40
rp_suman11-Apr-08 4:40 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Manfr3d11-Apr-08 5:05
Manfr3d11-Apr-08 5:05 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
rp_suman11-Apr-08 5:20
rp_suman11-Apr-08 5:20 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Manfr3d11-Apr-08 6:44
Manfr3d11-Apr-08 6:44 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Bram van Kampen11-Apr-08 12:33
Bram van Kampen11-Apr-08 12:33 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Manfr3d11-Apr-08 22:33
Manfr3d11-Apr-08 22:33 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Bram van Kampen13-Apr-08 3:21
Bram van Kampen13-Apr-08 3:21 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Manfr3d13-Apr-08 9:30
Manfr3d13-Apr-08 9:30 
GeneralRe: Compiling a Parser Generator generated file causes linker errors Pin
Bram van Kampen13-Apr-08 15:09
Bram van Kampen13-Apr-08 15:09 
GeneralDividing the bits in a 16 bit short value Pin
ChemmieBro11-Apr-08 2:28
ChemmieBro11-Apr-08 2:28 
GeneralRe: Dividing the bits in a 16 bit short value Pin
JudyL_MD11-Apr-08 2:42
JudyL_MD11-Apr-08 2:42 
GeneralRe: Dividing the bits in a 16 bit short value Pin
CPallini11-Apr-08 3:30
mveCPallini11-Apr-08 3:30 
GeneralRe: Dividing the bits in a 16 bit short value Pin
ChemmieBro11-Apr-08 4:15
ChemmieBro11-Apr-08 4:15 
GeneralRe: Dividing the bits in a 16 bit short value Pin
CPallini11-Apr-08 4:41
mveCPallini11-Apr-08 4:41 
GeneralRe: Dividing the bits in a 16 bit short value Pin
ChemmieBro11-Apr-08 4:48
ChemmieBro11-Apr-08 4:48 
Questionhow to set background color in visual studio 2005 and how to call matlab by MFC/C++?? Pin
johndoelee11-Apr-08 1:58
johndoelee11-Apr-08 1:58 

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.