473,883 Members | 1,524 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 125287

"CBFalconer " <cb********@yah oo.com> wrote in message
This really is the exception that proves the point. A platform
that disallows native machine langauge programs cannot really be
said to have a compiler. Nor is C the ideal language for such an
environment - you need something which does memory
management for you.


Nonsense. There are various environments that do precisely that.
Ones known to me include:

UCSD p-code system
My own pcd system
Verifone terminals
Java Bytecode machines

all of which port binary executable modules across widely
differing machine architectures. Only the Verifone system was
specifically designed to accommodate C.

Well let's say we have a c interpreter. Someone decides to make the system a
bit more efficient, and strip out comments before passing the source to the
interpreter. Is the comment stripper a "compiler?" .
Someone decides to speed things up a little bit more and tokenize the C
keywords (i.e. we use non-ASCII characters to represent "if" and "for" etc).
Is the tokenizer a compiler?
See where this is leading? At some point we will arrive at a "binary
executable module" and you will say "this is a compiler". But extension of
the word to marginal cases is arbitrary.
Of the examples you give only one supports C, suggesting that C isn't a good
langauge for interpreted bytecodes.
Why is memory management a good idea in these environments? Consider a
linked list. In C the user sets up the pointers himself. This means that
every time you traverse the list it is necessary to check each pointer for
validity. You also have problems because the addresses of the pointers
themselves are taken, so you need some system to prevent the pointers being
corrupted. This adds up to quite a lot of overhead.
In a language that manages memory for you, linked lists can be provided as
built in strutures. The user has no way of accessing the pointers, so
internally they can be represented as raw addresses with perfect safety.
Nov 14 '05 #61
Malcolm <ma*****@55bank .freeserve.co.u k> scribbled the following:
"CBFalconer " <cb********@yah oo.com> wrote in message
> This really is the exception that proves the point. A platform
> that disallows native machine langauge programs cannot really be
> said to have a compiler. Nor is C the ideal language for such an
> environment - you need something which does memory
> management for you.
Nonsense. There are various environments that do precisely that.
Ones known to me include:

UCSD p-code system
My own pcd system
Verifone terminals
Java Bytecode machines

all of which port binary executable modules across widely
differing machine architectures. Only the Verifone system was
specifically designed to accommodate C.

Well let's say we have a c interpreter. Someone decides to make the system a
bit more efficient, and strip out comments before passing the source to the
interpreter. Is the comment stripper a "compiler?" .


Well, as much a compiler as the C preprocessor is. The resulting code
is also valid C source.
Someone decides to speed things up a little bit more and tokenize the C
keywords (i.e. we use non-ASCII characters to represent "if" and "for" etc).
Is the tokenizer a compiler?
Only a bit more than the comment stripper was.
See where this is leading? At some point we will arrive at a "binary
executable module" and you will say "this is a compiler". But extension of
the word to marginal cases is arbitrary.


I still think of javac (translating Java source code into bytecode) as
a compiler, even though you can't directly execute bytecode.
Look at it another way - isn't the distinction "only a translator that
outputs natively executable code can be called a compiler" also
arbitrary? Why single out natively executable code? The C compiling
process distinguishes between compiling and linking. Is the pure
compiler not a compiler, because unlinked object files aren't natively
executable?

(BTW, you forgot to ask if UNIX cat was a compiler. After all, it takes
in source code and outputs source code.)

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
Nov 14 '05 #62
Malcolm wrote:
At some point we will arrive at a "binary
executable module" and you will say "this is a compiler".


It has to be compiler before that point.
You can compile C files, which are not complete programs,
and the output is not executable.

--
pete
Nov 14 '05 #63
"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
[...]
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.

[...]

I know very little about the AS/400. I've never used one. But (and
this is just a wild guess), if a system has 16-byte pointers, perhaps
it would be designed so it can deal with them efficiently, either by
having 16-byte registers, or by having a large number of registers and
the ability to use several of them together, or by designing it so
that thrashing memory isn't a problem, or by doing some other very
clever thing that I haven't thought of, or by having a user community
that doesn't care that much about blazing speed.

Malcolm, unless you're much more familiar with the AS/400 than I am
(and more familiar with it than you've let on so far in this thread),
you might consider refraining from detailed speculation about it.
Discussions of AS/400 architecture are marginally topical here,
because they can illuminate the range of systems on which C can be
implemented and the assumptions (like word-sized pointers) that may
not be universally valid. But I suggest such discussions should be
based on actual knowledge of the architecture.

As for exceptions proving rules, the actual origin of the saying isn't
particularly relevant. One common use of it is that an exception
actually strengthens a rule -- for example, that finding a black swan
makes the statement that "all swans are white" more valid. This is,
of course, nonsense. When you used a variant of the saying upthread,
you gave the impression, probably unintentionally , that you were using
it in that common nonsensical way. I suggest we drop the discussion
of the origin of the saying (or take it to alt.usage.engli sh) and
instead talk about what you actually meant.

What I think you actually meant is that because the C translation
system on the AS/400 doesn't generate machine code it's not a true
compiler. The issue is the meaning of the word "compiler". The C99
standard doesn't define the word compiler (it only uses it briefly in
one footnote), and I think the C90 standard is similar. Most of the
participants in this thread seem to think that a translator that
generates something other than machine code can legitimately be called
a compiler. There's a quote from Aho, Sethi, and Ullman that agrees
with that point of view. It might be time for you to drop the
argument unless you can actually prove that you're right and the rest
of us are wrong. This might also be a better topic for
alt.usage.engli sh.

As far as the standard is concerned, the C translation system on the
AS/400, whatever we call it, is part of the implementation, along with
the library, the OS, and whatever else is needed to make C programs
run.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #64
In <40************ ***@yahoo.com> CBFalconer <cb********@yah oo.com> writes:
Malcolm wrote:

... snip ...
>

Well every system I know uses fixed-size pointers. There is one
main exception to the rule that the size of the pointer represents ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^ the size of the address space, and that's quite an important one, ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ old x86 compilers with their segmented architecture.


No exception at all. Such systems either restricted the size of
the data area to 64k (which is adequately handled by a 16 bit
pointer) or used a 32 bit pointer.


Engage your brain, Chuck! The 8086 machines have a 20-bit address space
and their pointers have either 16 or 32 bits. In neither case, the
pointer size reflects the size of the address space.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #65
On Mon, 16 Feb 2004 22:35:31 -0000
"Malcolm" <ma*****@55bank .freeserve.co.u k> wrote:
"CBFalconer " <cb********@yah oo.com> wrote in message
This really is the exception that proves the point. A platform
that disallows native machine langauge programs cannot really be
said to have a compiler. Nor is C the ideal language for such an
environment - you need something which does memory
management for you.
Nonsense. There are various environments that do precisely that.
Ones known to me include:

UCSD p-code system
My own pcd system
Verifone terminals
Java Bytecode machines

all of which port binary executable modules across widely
differing machine architectures. Only the Verifone system was
specifically designed to accommodate C.

Well let's say we have a c interpreter. Someone decides to make the
system a bit more efficient, and strip out comments before passing the
source to the interpreter. Is the comment stripper a "compiler?" .
Someone decides to speed things up a little bit more and tokenize the
C keywords (i.e. we use non-ASCII characters to represent "if" and
"for" etc). Is the tokenizer a compiler?
See where this is leading? At some point we will arrive at a "binary
executable module" and you will say "this is a compiler". But
extension of the word to marginal cases is arbitrary.


I would suggest that a C compiler is a program that performs a
translation on the source code producing such diagnostics as required
by the standard such that if it was a valid source file when linked to
produce something the C standard says should be executable it can be
executed by the target environment. If the code is byte code, assembler
or anything else that is irrelevant.
Of the examples you give only one supports C, suggesting that C isn't
a good langauge for interpreted bytecodes.
Pascal is a compiled language and I've used a UCSD Pascal system.
Why is memory management a good idea in these environments? Consider a
linked list. In C the user sets up the pointers himself. This means
that every time you traverse the list it is necessary to check each
pointer for validity.
If you are talking about the byte code interpreter (or whatever) then
you are wrong. The C standard allows your environment to crash or do
anything else it happens to do if you use an invalid pointer.
You also have problems because the addresses of
the pointers themselves are taken, so you need some system to prevent
the pointers being corrupted. This adds up to quite a lot of overhead.
The byte code interpreter (or whatever) does NOT have to do that. It can
crash if your executable gets it wrong.
In a language that manages memory for you, linked lists can be
provided as built in strutures. The user has no way of accessing the
pointers, so internally they can be represented as raw addresses with
perfect safety.


For perfect safety it still has to do array bounds checking etc
otherwise you might have run off the end of an array and corrupted your
pointer, and if you don't then check your pointer who knows what will
happen?

A C implementation that uses some form of interpreter can do as little
checking as a C implementation that compiles to native machine code and
still be no less safe. However, systems like UCSD can provide the
ability to distribute binaries without knowing anything about the target
environment apart from it having a suitable interpreter.

Also, a lot of modern processors run microcode programs that interpret
the machine code, so even if you compile to machine code you could well
still have your program running under an interpreter.
--
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 #66
Joona I Palaste <pa*****@cc.hel sinki.fi> scribbled the following:
Malcolm <ma*****@55bank .freeserve.co.u k> scribbled the following:
Well let's say we have a c interpreter. Someone decides to make the system a
bit more efficient, and strip out comments before passing the source to the
interpreter. Is the comment stripper a "compiler?" .
Well, as much a compiler as the C preprocessor is. The resulting code
is also valid C source. Someone decides to speed things up a little bit more and tokenize the C
keywords (i.e. we use non-ASCII characters to represent "if" and "for" etc).
Is the tokenizer a compiler? Only a bit more than the comment stripper was. See where this is leading? At some point we will arrive at a "binary
executable module" and you will say "this is a compiler". But extension of
the word to marginal cases is arbitrary.

I still think of javac (translating Java source code into bytecode) as
a compiler, even though you can't directly execute bytecode.
Look at it another way - isn't the distinction "only a translator that
outputs natively executable code can be called a compiler" also
arbitrary? Why single out natively executable code? The C compiling
process distinguishes between compiling and linking. Is the pure
compiler not a compiler, because unlinked object files aren't natively
executable? (BTW, you forgot to ask if UNIX cat was a compiler. After all, it takes
in source code and outputs source code.)


Actually, a good definition for a compiler might be a translator for
translating a higher-level program into a lower-level one. If the
languages are of the same level it's a (pre)processor. If their levels
are the other way around it's a decompiler.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The large yellow ships hung in the sky in exactly the same way that bricks
don't."
- Douglas Adams
Nov 14 '05 #67

"Keith Thompson" <ks***@mib.or g> wrote in message
I know very little about the AS/400. I've never used one. But (and
this is just a wild guess), if a system has 16-byte pointers, perhaps
it would be designed so it can deal with them efficiently, either by
having 16-byte registers, or by having a large number of registers and
the ability to use several of them together, or by designing it so
that thrashing memory isn't a problem, or by doing some other very
clever thing that I haven't thought of, or by having a user community
that doesn't care that much about blazing speed.
Obviously I don't know exactly how the AS/400 works, but I do know that if
pointers are 16 bytes then they will be slow. Since the pointer contains
bounds information as well as a validity bit then you need at least three
registers to process it (address, bounds, validity) even if the registers
are 128 bits wide. Unless of course the various pieces of information can be
combined in one instruction, but then the bytecode is supposed to be
platform independent, sp using something that can only be implemeted
efficiently on special hardware is cheating.
As for exceptions proving rules, the actual origin of the saying isn't
particularly relevant. One common use of it is that an exception
actually strengthens a rule -- for example, that finding a black swan
makes the statement that "all swans are white" more valid. This is,
of course, nonsense. When you used a variant of the saying
upthread,you gave the impression, probably unintentionally , that you
were using it in that common nonsensical way. I suggest we drop the
discussion of the origin of the saying (or take it to alt.usage.engli sh)
and instead talk about what you actually meant.
I'd agree. The problem is that some people's grasp of proverbs is so bad
that you've got to explain everything. The AS/400 is an exception to the
rule that no implementation stores bounds information with pointers, but it
is such an oddball, not even compiling to machine code, that it doesn't
really invalidate the point that I was trying to make.

[ "compiler" ]
If you look at the literature you'll find "compiler" defined as something
that outputs machine code, or as something that translates a language into
another representation. You can use the latter definition if you wish, but
be aware that you are moving from the core definition of the term.
Nov 14 '05 #68

"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.
Nov 14 '05 #69
>> 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.


Some released programs are *SUPPOSED* to crash under appropriate
circumstances (like when you explicitly ask it to). The main reason
for this is apparently to permit sending this info back to the
maintainer so he can fix it. Yes, these features ARE sometimes left
in production and relased code.

For example, C has the abort() function.
GDB (the GNU debugger) has the "maintenanc e dump-me" command.
UNIX permits sending SIGQUIT to programs (unless the programs specifically
catch that signal) to cause a core dump, using a keystroke.

I do recall hearing some discussion about emulators for certain CPUs being
written so carefully that they emulated bugs in the actual hardware that
they were emulating precisely, if you asked it to emulate that particular
model of CPU. Anyone for emulating the Pentium math bug on a non-buggy
Pentium? Some of them also emulated lockups (which sounds to me like a
crash, as the only way out was RESET or power-cycle) just like the real thing.

Gordon l. Burditt
Nov 14 '05 #70

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
9936
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
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
10845
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
10412
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...
0
9571
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7970
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
7123
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();...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3231
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.