473,883 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

size of a sizeof(pointer)

what is the size of a pointer?

suppose i am writing,
datatype *ptr;
sizeof(ptr);
now what does this sizeof(ptr) will give? will it give the size of the
data the pointer is pointing to?

if no, can you give an counter example?

basically , i want to know what is the meaning of size of a ponter.

as you know

sizeof(int)=4;

sizeof(char)= 2;

but what does sizeof(ptr) means??

can anybody explain?
Nov 14 '05
79 125285
On Tue, 17 Feb 2004 23:03:00 -0000
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote:

"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
The byte code interpreter (or whatever) does NOT have to do that. It
can crash if your executable gets it wrong.

If a release program crashes on any input whatsoever then it is
bugged. This includes interpreters, decompressors, video games, or
whatever.


Not always. As far as the C standard is concerned there is nothing wrong
with an implementation containing an interpreter that crashes when a
program invokes Undefined Behaviour.

IMHO if that interpreter is something like a Virtual Machine that gets
invoked specifically to run a program and terminates when that program
terminates, then there is nothing wrong with it crashing on Undefined
Behaviour of the program being run, and this is no worse than the
program crashing if it was not running under a VM.
--
Flash Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spam, it is real and I read it.
Nov 14 '05 #71


Flash Gordon wrote:
On Tue, 17 Feb 2004 23:03:00 -0000
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote:

"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
The byte code interpreter (or whatever) does NOT have to do that. It
can crash if your executable gets it wrong.


If a release program crashes on any input whatsoever then it is
bugged. This includes interpreters, decompressors, video games, or
whatever.



Not always. As far as the C standard is concerned there is nothing wrong
with an implementation containing an interpreter that crashes when a
program invokes Undefined Behaviour.

IMHO if that interpreter is something like a Virtual Machine that gets
invoked specifically to run a program and terminates when that program
terminates, then there is nothing wrong with it crashing on Undefined
Behaviour of the program being run, and this is no worse than the
program crashing if it was not running under a VM.


While the standard is (rightly) unconcerned, as a possible
user of the VM which crashes, I am very concerned.
It has nothing to do with the language, per se, but
is a QOI issue. Given two VM's, one which crashed,
and another which issued a diagnostic, which would
you choose?

--

"It is impossible to make anything foolproof because fools are so
ingenious" - A. Bloch

Nov 14 '05 #72
On Wed, 18 Feb 2004 17:55:35 GMT
Nick Landsberg <hu*****@att.ne t> wrote:
Flash Gordon wrote:


<snip C VM crashing on undefined behaviour in application>
IMHO if that interpreter is something like a Virtual Machine that
gets invoked specifically to run a program and terminates when that
program terminates, then there is nothing wrong with it crashing on
Undefined Behaviour of the program being run, and this is no worse
than the program crashing if it was not running under a VM.


While the standard is (rightly) unconcerned, as a possible
user of the VM which crashes, I am very concerned.
It has nothing to do with the language, per se, but
is a QOI issue. Given two VM's, one which crashed,
and another which issued a diagnostic, which would
you choose?


That depends on the situation and the other aspects of the VMs. If the
one that crashed on Undefined Behaviour was significantly less resource
hungry then, having eliminated UB from the code, I might use it in
situations where no one would see the the messages produced by the other
one. If it also allowed me to hook in to things like segmentation
violations but the other did not let be trap any instances of Undefined
Behaviour, then I would be even more likely to use it.

In short, it depends.
--
Flash Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spam, it is real and I read it.
Nov 14 '05 #73

"Flash Gordon" <sp**@flash-gordon.me.uk> wrote in message
That depends on the situation and the other aspects of the VMs. If
the one that crashed on Undefined Behaviour was significantly less
resource hungry then, having eliminated UB from the code, I might
use it in situations where no one would see the the messages
produced by the other one.
It depends why you are using a VM. If the reason is portability of the
binary, then you might accept crashing. However if the reason is safety,
then undefined behaviour introduces potential security risks.
If it also allowed me to hook in to things like segmentation
violations but the other did not let be trap any instances of Undefined
Behaviour, then I would be even more likely to use it.

The problem is that the interpreter is the program that crashes. So if you
look at the core dump, or whatever a crashed program produces on your
system, you see where the interpreter failed to check for a out of bounds
array access, for example, but not where that array was in the bytecode.
Of course a decent interpreter would produce a better diagnostic than an
unspecified "illegal memory access".
Nov 14 '05 #74


Right. I've been tied up with work and have not had time to return to
this squabble, which is OT for c.l.c and fairly pointless anyway. I'll
respond to some specific points in this message if I feel I need to do
so, but on the whole I'd like to propose the following:

1. Most C implementations do not check pointer validity.
2. Some, however, do; the three I named for the AS/400 are examples.
3. I feel that (2) is a significant exception to (1).
4. You do not.
5. The origin and preferred usage of the phrase "the exception that
proves the rule" is disputed.
6. However, some people - including myself and some other c.l.c
readers - feel that when that phrase is used to mean "an
exception to a general rule demonstrates the validity of that
rule in other cases", it's somewhat lacking in rhetorical power.
Other people, of course, may feel differently.

Fair enough?

In article <c0**********@n ews6.svr.pol.co .uk>, "Malcolm" <ma*****@55bank .freeserve.co.u k> writes:

"Michael Wojcik" <mw*****@newsgu y.com> wrote in message

In article <c0**********@n ewsg2.svr.pol.c o.uk>, "Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
It is by some of us. And I'm well aware of how language works,
thanks.

Ho ho. So you understand how language works do you?


Well enough. I'm ABD in critical theory (and twentieth century
Anglophone prose). I've studied structural linguistics, socio-
linguistics, pragmatics, speech act theory, and poststructurali st
linguistics (as well as various fields that are arguably cognate).
I've read a good bit of philology. My fiance is a professor of
rhetoric in one of the top rhetoric departments in the US, so I spend
quite a lot of time discussing language with other folks familiar
with the subject. I don't need J. Random Poster to tell me that
etymology doesn't determine current use.
See the other threads on bounds checking. There is no point using C if it
does not compile to efficient code, just as there is no point having a
sports car if you are driving it down a traffic-calmed street.


I disagree that the only justification for using C is efficiency of
the resulting code. In my work, for example, I generally have to
produce code which can be ported to various other platforms by other
developers; I am limited in the demands I can put on them, and they
currently deal with C and COBOL. Given that choice, I'll take C.

And since portability is a huge concern in my work - a portation
problem in one component can stall the build "pipeline" for everyone
- the C matters that c.l.c deals with are the ones that I care about
the most.

An example: Chris Torek corrected my use of vsnprintf some months
back, which let me fix a nasty memory-corruption bug in Linux/390.
My error was not "restarting " va-processing with va_end and va_start
between calls to vsnprintf. That's a harmless error in many
implementations , but in some implementations va_arg is destructive
and trying to iterate through the argument list again invokes nasal
demons. That's why the standard forbids it - a point I missed in
my original code.
Pointers in the various AS/400 C implementations are 16 bytes
long. Why should passing such an object be "very slow"?

Because registers are probably 32 bits, and there are probably not too many
of them, so you will thrash memory.


You miss my point. Making *any* guess about how the AS/400 C
implementations work under the covers is taking a stab in the dark,
and likely to mislead you. It doesn't matter how large CPU registers
are in AS/400 C, because (at least in "classic" EPM C) function calls
didn't use them anyway. They weren't accessible to the implementation.
So C's use of 128-bit pointers (ie "native" MI pointers) didn't have
any noticeable adverse effect on performance for any normal program.
--
Michael Wojcik mi************@ microfocus.com

An intense imaginative activity accompanied by a psychological and moral
passivity is bound eventually to result in a curbing of the growth to
maturity and in consequent artistic repetitiveness and stultification.
-- D. S. Savage
Nov 14 '05 #75

"Michael Wojcik" <mw*****@newsgu y.com> wrote in message

1. Most C implementations do not check pointer validity. True. 2. Some, however, do; the three I named for the AS/400 are
examples. True. 3. I feel that (2) is a significant exception to (1). Fair enough. 4. You do not.
I feel it is a special case, because the C does not compile to machine code. 5. The origin and preferred usage of the phrase "the exception that
proves the rule" is disputed.
The origin may be the legal principle, but etymology isn't meaning. The
proverb is used in two ways, ignorantly to mean that "if a rule has an
exception then that proves the rule must be valid" and correctly "by looking
at seeming exceptions we tell if the rule is valid or not".
6. However, some people - including myself and some other c.l.c
readers - feel that when that phrase is used to mean "an
exception to a general rule demonstrates the validity of that
rule in other cases", it's somewhat lacking in rhetorical power.
Other people, of course, may feel differently.

It's the difference between the rule "all mammals are viviparous" and "no
mammals are eusocial". Both have exceptions. When we look at oviparous
mammals, the monotremes, we see that they belong to a tiny group that split
off very early and is only included in "mammals" by definiton. We can use
the rule to predict that we won't find an oviparous cat. However when we
look at the eusocial mammals - naked mole rats and, partially, wolves - we
see that there does not appear to be anything special about them. There
doesn't seem to be anything about being a mammal that precludes eusociality,
and if we found a new species of cat we can't be sure it won't be eusocial.


Nov 14 '05 #76
On 15 Feb 2004 18:55:20 GMT, Chris Torek <no****@torek.n et> wrote:
<snip>
Given that we have the word "translator ", however, I personally
would tend to use that word for a system in which the "produce
something useful" step requires outside assistance, such as a
C++-to-C step that not only does not come with a C compiler, but
is provided for a computer for which no C compiler is even available.
It is probably also worth pointing out that there are a number% of
compilers that have produced C as their "assembly code", but in
all cases of which I am aware, that C code was not portable at all
-- you had to tell the XYZ-to-C step [implementation specifics] [%footnote: when I say "a number" I do mean "more than one". While
cfront is perhaps the best-known example, I believe Xerox PARC had
C back-ends for some of their compilers, for the language that was
a followon to Mesa -- I have forgotten its name -- and for Modula-3,
for instance.]


"most" Eiffels. At least one Ada which I believe is still sold. f2c,
and I think p2c. I believe all Objective C's, and Comeau C++.

And of course any number (well, not *any* <G>) of tools which produce
C code from some other kind of program decription or specification,
like UML or flowcharts or logic diagrams etc. etc., although we (IME)
usually call those generators rather than translators or compilers.

- David.Thompson1 at worldnet.att.ne t
Nov 14 '05 #77
On Tue, 10 Feb 2004 02:54:58 GMT, pete <pf*****@mindsp ring.com> wrote:
<snip>
You can't implement the whole standard library,
if sizeof(int) is one.

putchar(EOF) has to be able to return EOF
converted to an unsigned char value,
converted back to a nonnegative int.

http://groups.google.com/groups?selm...andrew.cmu.edu


No, it needs to return any unsigned char value (which need not and
normally does not include EOF) *or* EOF as a signed int. It apparently
was intended, and certainly is traditional, that these are distinct,
i.e. (int)UCHAR_MAX != EOF, but the standard doesn't require it, and
if not, programs using stdio have to be a lot more careful.

AFAWK implementations on which sizeof(int)==1 are all freestanding
ones on platforms where stdio isn't useful, or feasible, or both, so
the issue doesn't arise in practice. And since so few programs (and
programmers) are careful in this way, even if such a hosted (full)
implementation were created it wouldn't be popular unless it had some
huge other benefit(s).

- David.Thompson1 at worldnet.att.ne t
Nov 14 '05 #78
Dave Thompson wrote:

On Tue, 10 Feb 2004 02:54:58 GMT, pete <pf*****@mindsp ring.com> wrote:
<snip>
You can't implement the whole standard library,
if sizeof(int) is one.
No


That's what they said on comp.std.c too.
I won't be making hosted sizeof(int) claim again.

--
pete
Nov 14 '05 #79
In article <ed************ *************** *****@4ax.com>,
Dave Thompson <da************ *@worldnet.att. net> wrote:
On 15 Feb 2004 18:55:20 GMT, Chris Torek <no****@torek.n et> wrote:
<snip>
Given that we have the word "translator ", however, I personally
would tend to use that word for a system in which the "produce
something useful" step requires outside assistance, such as a
C++-to-C step that not only does not come with a C compiler, but
is provided for a computer for which no C compiler is even available.
It is probably also worth pointing out that there are a number% of
compilers that have produced C as their "assembly code", but in
all cases of which I am aware, that C code was not portable at all
-- you had to tell the XYZ-to-C step [implementation specifics]

[%footnote: when I say "a number" I do mean "more than one". While
cfront is perhaps the best-known example, I believe Xerox PARC had
C back-ends for some of their compilers, for the language that was
a followon to Mesa -- I have forgotten its name -- and for Modula-3,
for instance.]


"most" Eiffels. At least one Ada which I believe is still sold. f2c,
and I think p2c. I believe all Objective C's, and Comeau C++.

And of course any number (well, not *any* <G>) of tools which produce
C code from some other kind of program decription or specification,
like UML or flowcharts or logic diagrams etc. etc., although we (IME)
usually call those generators rather than translators or compilers.


Indeed there are many. Another is CCsh, a Bourne Shell compiler
that Comeau also sells. Actually, the C code it produces is
extraordinarily portable, however, it depends, heavily, upon a
platform specific library to go along with it, so in the end there
is no escaping it :)
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 14 '05 #80

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

Similar topics

12
4737
by: Ellarco | last post by:
``Opaque-pointer representing the ID of an object. struct _objID; typedef struct _objID * objectID;'' Hi again. Im using an api that defines an objectID type. The above represents the extent of the documentation on it. The above means that objectID is defined as a pointer to an as yet undefined class/struct _objID, and, if I understand the term correctly, is opaque in
9
10697
by: dati_remo | last post by:
Hi, is it possible to find the dimension of an array using a pointer? main() { int a; f(a); return; }
19
8059
by: junky_fellow | last post by:
Can the size of pointer variables of different type may be different on a particular architecture. For eg. Can the sizeof (char *) be different from sizeof(int *) or sizeof (void *) ? What is the purpose of using a void pointer ? Instead of declaring a pointer variable "void *", can I declare it as "char *" and then later on typcast it to whatever type
33
17551
by: siliconwafer | last post by:
What is size of pointer in C on DOS? is it sizeof(int ) or size of (long int)? If this ans is present in FAQ pls direct me to tht ouestion
16
15677
by: Alex Vinokur | last post by:
Does it have to be? : sizeof (size_t) >= sizeof (pointer) Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
0
9934
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9789
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10840
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10409
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7969
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 presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7120
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4214
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.