473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Sizeof ponters

I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?

Nov 3 '07 #1
7 1287
Subriemanian wrote, On 03/11/07 23:01:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?
Completely, totally and utterly wrong. Pointers to different types can
be of different sizes. On most modern 64 bit implementations an int is
32 bits but a pointer is 64 bits. A fairly common series of processors
in one of its modes of operations uses a segmented architecture with
overlapping segments, so multiple bit patters point to the same address,
the architecture I am thinking of is the Intel 80x86.
--
Flash Gordon
Nov 4 '07 #2
Subriemanian wrote:
>
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?
Wrong. And wrong.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 4 '07 #3
On Nov 4, 4:01 am, Subriemanian <s...@invalid.comwrote:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?
It can be of same size or of different size.
Varies based on architecture/implementation.

This is a frequently asked interview question :):)

Karthik Balaguru

Nov 4 '07 #4
>>I have been thinking that all pointers(to any obejct) have the same
>size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?

both of these are architecture dependent.

however, as it so happens, both are true for 32 bit x86 (except in certain
edge cases, such as an x86-based AS/400, ...).
It isn't true for Large Model 32-bit x86, where pointers are 48 bits.
That isn't used much, though.
>only the former is true for x86-64 (where int remains 32 bits, but pointers
are 64 bits).
MS-DOS on x86 used 16-bit configurations where int is 16 bit, data
pointers were 16 bit or 32 bit, and code pointers were 16 bit or
32 bit, in 4 possible combinations.

Nov 4 '07 #5
Subriemanian wrote:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?
Short response: Wrong. Next question.

Long response: Consider reading the FAQ and looking in Google Groups'
archive for this group - this is discussed periodically and your
misconception can be dealt with simply by some basic research...
Nov 5 '07 #6
Subriemanian wrote:
I have been thinking that all pointers(to any obejct) have the same
size.
Wrong -- they /may/ all have the same size, but it's not /required/
that they all have the same size, and there have been implementations
in which they /did not/ all have the same size. (Hint: not all machines
use byte addresses.)
The size of a pointer is the size of an Int.
(You mean `int`, right?) Wrong: that's not required.
This is beause a memory location is addressed by an Int.
What's an `Int`?
Is that right/wrong?
It's wrong /in general/, although it may happen to be true on a particular
implementation, such as many common desktop implementations.

--
Chris "prime" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Nov 5 '07 #7

"Gordon Burditt" <go***********@burditt.orgwrote in message
news:13*************@corp.supernews.com...
>>>I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?

both of these are architecture dependent.

however, as it so happens, both are true for 32 bit x86 (except in certain
edge cases, such as an x86-based AS/400, ...).

It isn't true for Large Model 32-bit x86, where pointers are 48 bits.
That isn't used much, though.
yes, but then again, I will regard this as an edge case...
in my case, I was generally excluding edge cases.

>>only the former is true for x86-64 (where int remains 32 bits, but
pointers
are 64 bits).

MS-DOS on x86 used 16-bit configurations where int is 16 bit, data
pointers were 16 bit or 32 bit, and code pointers were 16 bit or
32 bit, in 4 possible combinations.
yes.
maybe I should have further specified that by x86 I meant:
x86 in 32 bit flat-model protected mode.

anymore, development of real-mode, big-real, or segmented 16/32-bit
protected-mode apps is fairly rare...

likewise, people, will usually state that they are developing specifically
for DOS or RM (or sometimes, i86), rather than using the more general term
of x86.

this is even more the case for '32 bit x86', which can be assumed to exclude
these other options.
x86-64, well, implies an x86-64 processor operating in long mode (if not in
long mode, I will still regard it as x86, as is also the case for legacy
mode).
or such...

Nov 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sunil Menon | last post by:
Dear All, A class having no member variables and only a method sizeof(object) will return 1byte in ANSI and two bytes in Unicode. I have the answer for this of how in works in ANSI. But I don't...
2
by: Xiangliang Meng | last post by:
Hi, all. What will we get from sizeof(a class without data members and virtual functions)? For example: class abnormity { public: string name() { return "abnormity"; }
19
by: Martin Pohlack | last post by:
Hi, I have a funtion which shall compute the amount for a later malloc. In this function I need the sizes of some struct members without having an instance or pointer of the struct. As...
21
by: sugaray | last post by:
hi, it just came up my mind that since we can get the length of any given string literal S with 'sizeof S-1', so, what's the merit of library function strlen()'s existence ? thanx in advance for...
9
by: M Welinder | last post by:
This doesn't work with any C compiler that I can find. They all report a syntax error: printf ("%d\n", (int)sizeof (char)(char)2); Now the question is "why?" "sizeof" and "(char)" have...
7
by: dam_fool_2003 | last post by:
#include<stdio.h> int main(void) { unsigned int a=20,b=50, c = sizeof b+a; printf("%d\n",c); return 0; } out put: 24
42
by: Christopher C. Stacy | last post by:
Some people say sizeof(type) and other say sizeof(variable). Why?
8
by: junky_fellow | last post by:
Consider the following piece of code: #include <stddef.h> int main (void) { int i, j=1; char c; printf("\nsize =%lu\n", sizeof(i+j));
90
by: pnreddy1976 | last post by:
Hi, How can we write a function, which functionality is similar to sizeof function any one send me source code Reddy
5
by: Francois Grieu | last post by:
Does this reliably cause a compile-time error when int is not 4 bytes ? enum { int_size_checked = 1/(sizeof(int)==4) }; Any better way to check the value of an expression involving sizeof...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.