Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / C++ Default Object "Pointer Value" question

Author
Message
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Dec 2007 22:02
Hi - Thanx for popping in.

I make an object declaration - say:

MyObjectDef *MyObject;

Now - I'm doing some debuggind I noticed ALL my uninitialized "pointers" are ALWAYS: 0xcdcdcdcd (hex)

Is this a "Constant Value?" or predefined thing from Microsoft? Seems to "ordered" to be a random occurance.

I mean - to answer my question - one would say - yeah its this constant: ?????? But - without knowing what ?????? is - I know it would be bad to use this value hardcoded.

So maybe I should set all unallocated pointers to ZERO - ??? This way I can test if they are in use or not by seeing if they equal zero versus testing for this 0xcdcdcdcd value.

Any thoughts?

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 13th Dec 2007 22:08 Edited at: 13th Dec 2007 22:12
Quote: "So maybe I should set all unallocated pointers to ZERO"

Always. As far as I'm aware, C++ compilers never set default values on their own.

You also haven't said whether you're declaring these pointers on the stack or not. If not, the compiler itself has a say on what the default value is, whereas if on the stack the default value has to be set at runtime (else the value will be whatever was on the stack before).

It should also be noted that for applications that are set up to be able to address above 2GB, 0xcdcdcdcd is a valid address.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Dec 2007 22:23
Thanx Ben - that's how I do it in FreePascal Also. Then I religiously set them to ZERO after a Delete object.

// freeepascal syntax
MyObject.Destroy;
MyObject:=nil; //nil= Pointer type - value of Zero

Login to post a reply

Server time is: 2024-10-08 18:16:34
Your offset time is: 2024-10-08 18:16:34