C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

POINTERS

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
akhilesh natani
Guest





PostPosted: Sat Sep 23, 2006 9:10 am    Post subject: POINTERS Reply with quote



hi sir,
sir i want to know a simple pointer concept.
Q) ..... when all of thw address are integer then why we uses the
pointer of type char,float etc.
Back to top
Salt_Peter
Guest





PostPosted: Sat Sep 23, 2006 9:10 am    Post subject: Re: POINTERS Reply with quote



akhilesh natani wrote:
Quote:
hi sir,
sir i want to know a simple pointer concept.
Q) ..... when all of thw address are integer then why we uses the
pointer of type char,float etc.

A pointer is an adress pointing to something that is not neccessarily
an integer. Just because a pointer itself occupies the same space as an
integer on *your* platform is nothing else but coincidence. Your CPU,
and the motherboard its attached to, is probably based on a 32 bit
address bus and a 32 bit data bus. My CPU, for example, is 64 bits.

A pointer without a type is in reality not a pointer anymore.

The type that a pointer is pointing to is critical. Consider a pointer
that is designed to point to a complex type. How can the compiler
allocate an instance of that type if it doesn't know about the type's
components + padding? Are all the houses in your town / city all the
same size? Yet, do they not use the same adressing system?

Lets say you are a contractor and you are charged with the task of
sending enough paint to cover the walls of a building at a given
mailing address (another type of pointer). How much paint would you
send to that address if you don't know whether the house at that
address is a bungalow, an apartment building or a 100 story highrise?
Back to top
Salt_Peter
Guest





PostPosted: Sun Sep 24, 2006 9:10 am    Post subject: Re: POINTERS Reply with quote



Stuart Golodetz wrote:
Quote:
"Salt_Peter" <pj_hern (AT) yahoo (DOT) com> wrote in message
news:1159000464.165628.42140 (AT) i3g2000cwc (DOT) googlegroups.com...
snip
Lets say you are a contractor and you are charged with the task of
sending enough paint to cover the walls of a building at a given
mailing address (another type of pointer). How much paint would you
send to that address if you don't know whether the house at that
address is a bungalow, an apartment building or a 100 story highrise?

[Thoroughly off-topic]
If money was no object, enough for the 100-storey high-rise. The rationale
being that that would certainly be enough for the apartment building or the
bungalow. I believe the correct name for the concept is "overkill" Smile

[back on topic]
Are you suggesting that a compiler should reserve all the memory
available on a system in order to allocatate a single element? Doesn't
it make more sense to know the type of building you'll be dealing with?
The overkill concept is not one that C++ has much respect for. Its a
concept that's dead and doesn't work.

Quote:

Incidentally, you could probably deduce something by thinking about who
asked you to bring the paint round. If it was a chap from down the pub,
chances are he doesn't want you to cover a 100-storey high-rise. If it was a
government official, he might not be interested in you painting his
bungalow. (Then again, he might...) You don't always need to know the type
of building explicitly, is my point.

Yes you do. Does it make sense to allocate an array of 1000 elements if
you only need 5? No. Does it makes sense to allocate a 64KB page when
you have no clue of the objects you'll be dealing with? No. So how the
hell are you going to write a program that will effiently allocate
resources if you don't know what type you are dealing with? Lets face
it, what are pointers used for? Does that not in fact impose the
dangerous concept of overkill? An address is just an address, its type
is far, far more important.

Quote:

Of course, none of this applies to programming as such, but the question was
asked :)

Regards,
Stu
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.