Click here to Skip to main content
15,886,842 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionpointer Pin
kumar sanghvi21-Aug-09 23:56
kumar sanghvi21-Aug-09 23:56 
AnswerRe: pointer [modified] Pin
Rajesh R Subramanian22-Aug-09 0:05
professionalRajesh R Subramanian22-Aug-09 0:05 
GeneralRe: pointer Pin
kumar sanghvi22-Aug-09 0:21
kumar sanghvi22-Aug-09 0:21 
GeneralRe: pointer Pin
Rajesh R Subramanian22-Aug-09 2:10
professionalRajesh R Subramanian22-Aug-09 2:10 
GeneralRe: pointer Pin
harold aptroot22-Aug-09 9:04
harold aptroot22-Aug-09 9:04 
GeneralRe: pointer Pin
Rajesh R Subramanian22-Aug-09 19:05
professionalRajesh R Subramanian22-Aug-09 19:05 
AnswerRe: pointer Pin
Rajesh R Subramanian22-Aug-09 19:06
professionalRajesh R Subramanian22-Aug-09 19:06 
AnswerRe: pointer Pin
harold aptroot23-Aug-09 7:54
harold aptroot23-Aug-09 7:54 
kumar sanghvi wrote:
int* p; //declared pointer to int (statement does nothing)<br />
int w=10; //declares and initializes an int to 10, but it won't exist unless you use it<br />
p=&10; //this is an error, you probably meant p=&w?

p=&w would do, assuming p is used: give (if it didn't have one yet) w a place on the stack (previously it would probably reside in a register), and set p to that address (eg lea esi, dword ptr[esp+24]), but if the operations on p are simple enough (for the specific implementation, not every theoretically simple enough sequence of operations) to evaluate at compile time it may be optimized to something weird and/or scary.

But it's fine to think of them as being on the stack, the compiler will guarantee that this assumption is true whenever you make it (and if you don't make it, it doesn't matter). They're definitely not on the heap, if that's what you were wondering about.


notes: many simplifications and omissions were made to avoid writing a king-sized post, if you really want to know every little detail you could ask the same question on comp.lang.c++[^], they will be happy to tell you every pedantic little detail. And I don't guarantee that anything in this post was actually true, use the information at your own risk (etc etc)



GeneralRe: pointer Pin
Rajesh R Subramanian23-Aug-09 8:13
professionalRajesh R Subramanian23-Aug-09 8:13 
GeneralRe: pointer Pin
harold aptroot23-Aug-09 8:40
harold aptroot23-Aug-09 8:40 
QuestionHRESULT:0x8007007E Pin
MozhdehQeraati21-Aug-09 18:32
MozhdehQeraati21-Aug-09 18:32 
AnswerRe: HRESULT:0x8007007E Pin
Code-o-mat21-Aug-09 22:03
Code-o-mat21-Aug-09 22:03 
AnswerRe: HRESULT:0x8007007E Pin
Hristo-Bojilov22-Aug-09 6:02
Hristo-Bojilov22-Aug-09 6:02 
GeneralRe: HRESULT:0x8007007E Pin
MozhdehQeraati23-Aug-09 18:11
MozhdehQeraati23-Aug-09 18:11 
GeneralRe: HRESULT:0x8007007E Pin
Hristo-Bojilov24-Aug-09 10:16
Hristo-Bojilov24-Aug-09 10:16 
QuestionCreating an object using a reference Pin
thelonesquirrely21-Aug-09 8:28
thelonesquirrely21-Aug-09 8:28 
AnswerRe: Creating an object using a reference Pin
Stuart Dootson21-Aug-09 9:48
professionalStuart Dootson21-Aug-09 9:48 
QuestionHow to join two data tables in different database Pin
jiabin_007_love21-Aug-09 7:17
jiabin_007_love21-Aug-09 7:17 
AnswerRe: How to join two data tables in different database Pin
David Crow21-Aug-09 9:24
David Crow21-Aug-09 9:24 
AnswerRe: How to join two data tables in different database Pin
jiabin_007_love21-Aug-09 18:16
jiabin_007_love21-Aug-09 18:16 
AnswerRe: How to join two data tables in different database Pin
David Crow22-Aug-09 16:43
David Crow22-Aug-09 16:43 
GeneralRe: How to join two data tables in different database Pin
jiabin_007_love23-Aug-09 16:22
jiabin_007_love23-Aug-09 16:22 
QuestionHow to get a Windows Service custom Status? [C++/C#] Pin
Shaitan0021-Aug-09 6:59
Shaitan0021-Aug-09 6:59 
QuestionIntercepting PlaySound Pin
Marc Clifton21-Aug-09 4:38
mvaMarc Clifton21-Aug-09 4:38 
AnswerRe: Intercepting PlaySound Pin
Randor 21-Aug-09 5:07
professional Randor 21-Aug-09 5: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.