Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 7th, 2006, 1:08 PM   #1
wel
Newbie
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0 wel is on a distinguished road
Pointer Storage

Hi, How does a pointer gets store in memory ?
wel is offline   Reply With Quote
Old Jun 7th, 2006, 1:13 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Same was as anything else; it gets assigned a memory location. This is most often referenced by a label, such as "myPtr." The pointer standing alone is useless and dangerous. Check the link in my signature for material on pointers.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 7th, 2006, 8:19 PM   #3
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
In 32-bit mode, the processor treats integer and pointer data-types the same*. You can cast a pointer to an integer and vice versa, although this is unwise!


*In 64-bit systems and "64-bit compliant" systems, a 64-bit pointer is used. On all systems, a pointer is represented by a numerical value. This is pretty intuitive.

Right?
Harakim is offline   Reply With Quote
Old Jun 7th, 2006, 8:28 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I'm sorry, Harakim, but your post is misleading and somewhat inaccurate and is, further, introducing some implementation-dependent information. Please be as careful as possible when imparting information to novices.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 7th, 2006, 9:03 PM   #5
wel
Newbie
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0 wel is on a distinguished road
Pointer

So, how big would the memory space be for the pointer same as an normal var per say an int?

Another question this one is a very silly one but I can't seem to find an answer to it.

On page 93 of "The C programming Language 2nd edition" well I can't undestand what they mean by the graphic at the bottom.

Thanks for the response.
wel is offline   Reply With Quote
Old Jun 7th, 2006, 9:20 PM   #6
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,122
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by wel
So, how big would the memory space be for the pointer same as an normal var per say an int?

Another question this one is a very silly one but I can't seem to find an answer to it.

On page 93 of "The C programming Language 2nd edition" well I can't undestand what they mean by the graphic at the bottom.

Thanks for the response.
On most common systems, sizeof(int) == sizeof(int *), but this isn't always true. As a case when it is not true, take old software running on an 80x86 platform that uses the segmented memory model. In this case, for a full pointer (aka 'far pointer'), it was 32 bits (two words, one each for segment and offset), whereas an int was often only 16 bits (one word).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is online now   Reply With Quote
Old Jun 8th, 2006, 6:24 AM   #7
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,254
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by lectricpharaoh
On most common systems, sizeof(int) == sizeof(int *), but this isn't always true.
On some common systems it is true, but on some other common systems it is not.
Quote:
Originally Posted by lectricpharaoh
As a case when it is not true, take old software running on an 80x86 platform that uses the segmented memory model. In this case, for a full pointer (aka 'far pointer'), it was 32 bits (two words, one each for segment and offset), whereas an int was often only 16 bits (one word).
The default pointer size used on older 8086 machines was 16 bit. Later on (80286 and later) the hardware was able to support 32 bit operations, and eventually some compilers evolved to take advantage of that. Initially, by default, those compilers supported 16 bit pointers (and referred to as "near" pointers). A far pointer, as you say was a (segment, offset) pair and, technically, not all far pointers were 32 bit pointers -- not all of the 32 bits were actually used.

All that aside, there is really little point in debating whether an int and a pointer are the same size, or which is the "common" usage. They are the same size on some target machines, and are different sizes on some other machines --- and both types of machines are quite common. So writing code that assumes they are the same size is asking for trouble: either you get "lucky" and run into trouble because your machine has int and pointers of different sizes. Or your get unlucky, and get a program that appears to run well, until you decide to port it to another machine or (even) to another compiler on the same machine.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC