From: RB on 4 Jun 2010 09:28 >You are confusing the constructor with allocation. ........... >Since you did not show the entire program there is no way to >tell what is going on here. Ugh well you are correct, I could not get my debugger to break on a point to show what you ask, and I grew tired of stepping thru long runs of framework. But in any case I think I have seen that a global is not located anywhere near the current stack frame and further you guys replied information that gives me clear delineation of where a Global (data section PE), Local (stack) or new (heap) implementation would be stored. From my studies and experiments it appears that the only difference between a Global implementation and a static implementation is one of program or file scope, correct ?
From: Oliver Regenfelder on 4 Jun 2010 09:36 Hello, RB wrote: > From my studies and experiments it appears that the only difference > between a Global implementation and a static implementation is > one of program or file scope, correct ? If you are revering to the static keyword applied to a global variable then the answer is yes. some_file.cpp: int myInt = 10; // global scope static int myFileInt = 11; // file scope, You can have a myFileInt in every .cpp file as long as they are all static. But if you have 2 myInt with global scope then the linker will complain about it. Best regards, Oliver
From: RB on 4 Jun 2010 09:42 Thanks for all the info. This all gives me a clearer picture of what is going on and helps me construct the total concept. I remember the data segment from my old (very simple) assembler programs, and a long time ago I read about the PE header sections, but really I just had no idea where the compiler was storing the different items, and I wanted to be sure that I was not missing any garbage cleanup, which as long as I don't use new it would appear I am covered on that with the exception of CreateObject, which I am currently studying which appears I would have to code a delete on that ptr when done. But again it appears that CreateObject is just a additional wrapper to new creation based on the runtime data of a CObject direvitive. No need to reply (unless of course you want to) since I need to read and experiement some more on the CRuntimeClass struct etc before I post any questions on that or the answers will go right over my head. I do however have all of those long macros expanded so I can see exactly what code there is.
From: RB on 4 Jun 2010 09:44 > Is there a reason you need to know the stack size? No not any more since all the informative replies I received. I was only trying to verify whether the address was in some other part of the stack. Also see my reply to your other reply this thread. And as always thanks Joe for all your help.
From: RB on 4 Jun 2010 10:42 > some_file.cpp: > int myInt = 10; // global scope > static int myFileInt = 11; // file scope, > > You can have a myFileInt in every .cpp file as long as they are all static. > But if you have 2 myInt with global scope then the linker will complain > about it. Best regards, Oliver Thanks Oliver, for verifying what I was surmizing to be the case. I realize some of my posts are ambiguous. But basically if it is global then it is a program (all files) scope, but static is only file scope, as in, // declared in global space // struct StaticStruct { int A, B, C, D; }; // Global variables int Global_Int ; //--------Begin Class --------// class Class1 { // Static Member Variables static int Class1_Static_Int; static StaticStruct classClass1; Class1( ) {} ~Class1( ) {} Class1(int IntArg) { Class1_Int = IntArg; Global_Int = IntArg; // appears I can initiaze a global var inside constructor Class1_Static_Int = IntArg; // but static vars appears must first be initialized // outside the class (and after class) at global location } }; //--------end of class -------// // static member initializations appears this cannot be done inside the class // constructor and must be done globally after class declaration in file int Class1::Class1_Static_Int = 0 ; StaticStruct Class1::classClass1 = { 1, 2, 3, 4}; // this appears similiar // access scenario as mfc's static CRuntimeClass. void main (void) { Whatever........; }
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Server Busy message during printing from Excel after Off. 2003 SP2 Next: VS2010 and HINSTANCES |