473,889 Members | 1,352 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 125292
(This is getting pretty far off topic and perhaps should move to
comp.programmin g or even the moderated group, comp.compilers. ..)
In article <c0**********@n ewsg3.svr.pol.c o.uk>
Malcolm <ma*****@55bank .freeserve.co.u k> writes:
Let's say someone produces a tool that converts C code to compliant C++
code - e.g. alters C++ keywords used as identifiers, adds prototypes, adds
explicit casts of void * etc. Would you describe such a program as a C
compiler? If not, why not?
Chris Torek wrote:
Generally, I *would* call it a compiler (provided it produced an
executable image in the process, perhaps by later invoking the
"assembler" that translates the C++ to machine code).

In article <news:c0******* ***@sparta.btin ternet.com>
Richard Heathfield <bi****@eton.po wernet.co.uk> writes:Well, it's obviously your prerogative to use words as you choose, but your
proviso here flies in the face of Aho, Sethi and Ullman's definition: "a
compiler is a program that reads a program written in one language - the
source language - and translates it to an equivalent program in another
language - the target language" - no mention there of executable images.
Source: Dragon Book (Chapter 1, page 1!)


As nrk points out in a followup, there is at least some disagreement
over precisely what a "compiler" is. I am happy to work with the
Dragon Book definition (which, to be honest, I had actually forgotten
-- it has, after all, been 20 years! :-) ) as well. In this case,
a translator much like the original "cfront" is also a compiler
even if it never produces an executable.

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 "this implementation has 32-bit
int, is big-endian, widens all floats to double, uses a stack for
variable arguments", and all sorts of other things tied to the
specific implementation. Thus, calling the C output an "equivalent
program" is perhaps stretching the truth: it is only "equivalent "
for one specific machine or group of machines, not for all systems
on which C runs.

Finally, let me note that this sort of thing is why it sometimes
pays to step back and define one's terms. People can argue forever
fruitlessly over nitpicky details, never reaching any agreement,
simply because they started with different definitions. This, in
fact, is why we have C standards: without a common definition of
what it is to "be" a C program, it may be impossible for two people
-- or even one person and a compiler -- to reach agreement as to
what the source-language program *means*.

[%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.]
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #51

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

"Chris Torek" <no****@torek.n et> wrote in message

Would you also claim that any machine on which the machine's
"opcodes" are interpreted by microcode has no compilers?
Let's say someone produces a tool that converts C code to compliant C++
code - e.g. alters C++ keywords used as identifiers, adds prototypes, adds
explicit casts of void * etc. Would you describe such a program as a C
compiler? If not, why not?
I posted a perfectly workable definition of "compiler" which easily
deals with this sort of case. A compiler is a software tool which
processes translation units (files, in many implementations - though
not in OS/400, for one) in their entirety (that's the "compilatio n"
process), converting them into a form more amenable for execution.
The compiler's output need not be directly executable by the OS - and
indeed in many cases is not - it just needs to be further along the
process.

If, for some reason, you have an implementation which supplies only
a C++ compiler, then a C-to-C++ translator would be a C compiler for
that system. It would serve to move C source translation units
further along the path to executable form.
Microcode creates a grey area.
Not if you have a sensible, consistent definition of "compiler".
I would say that the difference is between an
intermediate bytecode that is designed for arbitrary hardware, and a program
which is hardware-specific, although it relies on some microcode to support
that hardware.
The difference between what and what else?
Ultimately it's just a question of definition
Yes, that's what determines what a word, such as "compiler", means.
- how far can we extend the
term "compiler" until we're talking about two totally different things?
I'm afraid I don't see what "two totally different things" are under
discussion here. I might guess you mean, on the one hand, one of the
OS/400 C implementations , and on the other some C implementation more
familiar to you, but those strike me as two things which are not very
different at all.
The
AS/400 almost certainly contains a substantial amount of C code which is
compiled to native machine code and runs the OS.
How did you come by this information? The internals of OS/400 are for
the most part a closely guarded secret. Could it be that you are making
a wild, unsubstantiated guess?

(In point of fact, what I've heard informally from IBM insiders is that
the majority of the original OS/400 implementation was written in PL/I.
Rumor has it was substantially rewritten for the RISC implementation.
That's the LIC - Licensed Internal Code - which is the equivalent of the
kernel in OS/400 and is said to be the only part of the OS which is
native code. The bulk of the OS, including the shell and utilities, is
in theory compiled to MI. Again, this may have only been true in the
early implementations , with more pieces migrated to native code as the
OS evolved.)
How are we to distiguish
this compiler from the "compiler" shipped to customers?


Most obviously, in that it's not available to customers. And, of
course, it has a different target. What exactly is your point?

--
Michael Wojcik mi************@ microfocus.com

We are subdued to what we work in. (E M Forster)
Nov 14 '05 #52

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

"The exception proves the rule" is a famous proverb. "Prove" means "tests",
not "demonstrat es the point".
Yes, "prove" does sometimes mean "test". However, the phrase "the
exception proves the rule" does not use "prove" in this sense. See the
link I provided in my first reply. You are victim of a folk etymology.
Now I claimed that not a single compiler, to my knowledge, implemented safe
pointers. An exception was raised.
Well, that's what safe pointers are for, after all...
However on examination we see that the
"compiler" isn't really a compiler at all, if we define "compiler" as
"something that translates source code to machine code".
And if we define "compiler" as "person who assembles documents out
of individual pages", gcc isn't a compiler either.
So the exception actually demonstrates that the point is valid.


What it demonstrated was that your claim was wrong, and your definition
of "compiler" is overly restrictive and opportunistic, introduced solely
in an attempt to save a bogus argument.
--
Michael Wojcik mi************@ microfocus.com

This book uses the modern technology to explain the phenomemon in the world
of Japanese animation. If you love anime so much, you'd better read this.
After you read it, you may agree that is destroying the dream of the child.
Needs Chinese viewing system. -- The Goodboy Scientific
Nov 14 '05 #53

In article <cv************ *************** *****@4ax.com>, Mark McIntyre <ma**********@s pamcop.net> writes:
On 13 Feb 2004 20:49:18 GMT, in comp.lang.c , mw*****@newsguy .com (Michael
Wojcik) wrote:

That's not what that idiom means. "The exception proves the rule"
is a partial vernacular translation of a Latin legal principle


possibly. Its probably more likely that the saying uses the alternate
meaning of "prove" which is "test". As in the "proof of the pudding is in
the eating".


"more likely" according to whom? The consensus I've seen (in
alt.usage.engli sh and elsewhere) appears to be that that's a folk
etymology, albeit one popular with armchair pedants. The OED agrees
with the derivation from "exceptio probat regulam...", though it
admits that the phrase is "commonly" used with "the [substantive]
being interpreted in sense 2". But even this does not imply use
of "prove" as "test": the OED's "sense 2" for "exception" is simply
"a particular case which comes under the terms of a rule, but to
which the rule is not applicable". The OED's examples of this
usage do not use "prove" for "test", but rather are all cases of
just the sort of handwaving normally seen with casual use of the
phrase - a suggestion that the existence of an exception or two
just makes the rule "stronger" or more persuasive.[1]
1. _Oxford English Dictionary_, 2nd ed. See under "exception" .

--
Michael Wojcik mi************@ microfocus.com

I would never understand our engineer. But is there anything in this world
that *isn't* made out of words? -- Tawada Yoko (trans. Margaret Mitsutani)
Nov 14 '05 #54

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

"Michael Wojcik" <mw*****@newsgu y.com> wrote in message
This really is the exception that proves the point.
That's not what that idiom means.


Etymology isn't meaning. The proverb is not used in that way.


It is by some of us. And I'm well aware of how language works,
thanks. I was simply hoping to point out that you were employing a
bogus argument through an unfortunately popular turn of phrase,
apparently under the misapprehension that its common misuse made it
logically valid. Now it appears that you are simply unable to
understand that it's a bogus argument.
(By the way the etymology itself is dodgy)
http://www.icsi.berkeley.edu/~nchang...exception.html
Few things are crystal-clear in English etymology. The fact that
Nancy Chang happened upon one philologist who happened to think that
the phrase originally employed "prove" in the sense of "test" does
little to contradict the evaluations of more authoritive sources,
which agree with Bergen rather than Breen. And, frankly, I don't
see much validity to Breen's argument; derivation from German rather
than Latin does nothing to demonstrate that "prove" should be used
in the sense of "test".
It's not something in formal logic, but a rule of thumb.
Ah, my favorite form of argument. "It's not logical, just something
that's often kinda sorta right."
To see if a rule
applies, look at cases that appear to be exceptions.
That process falls quite nicely under logic. It's called "trying
to prove the thesis by negation of the converse". Unfortunately
for your argument, what it proves is that the converse is false.

Your examples don't demonstrate anything except the difference
between a universal rule and a general one. I fail to see how that's
germane to the argument, which is whether the various C implementa-
tions for the AS/400 are a counterexample to the thesis that "no C
implementations provide safe pointers". At least one exception
exists; the thesis is phrased as a universal rule and so is disproven.

Now, apparently, you want to convert this thesis into a general rule
("few C implementations provide safe pointers"), but since this is
an unremarkable statement, you hope to salvage its force by relegating
its exceptions to some second-class status. It's barely a step beyond
argument-by-sticking-one's-fingers-in-one's-ears.
Really. Care to expand upon this rather bizarre thesis? In what
way do the characteristics of the AS/400 1) make C any less "ideal"
there than on any other platform, or 2) require automatic memory
management?


Because C sacrifices safety in memory access for efficiency.


Chapter and verse, please. (Oh, I realize this is standard C lore.
But the language does not *depend* on this trade-off, and it has
many admirable qualities which have nothing to do with it.)
Since the
platform won't allow this, the safety has to be put in at an inappropriate
level. So I would guess that when writing a function to iterate over a
string, the pointer is checked for out-of-bounds at every increment.
Your guess would be wrong, in the general case.
Certainly passing a pointer, if it contains validity information, will be
very slow.
Pointers in the various AS/400 C implementations are 16 bytes long.
Why should passing such an object be "very slow"?
There ceases to be a point in using C on the AS/400, except that C is a very
popular language, and there is always a point in supporting a standard.
The presence of (at least) three commercial C implementations for the
AS/400, and AS/400 software developed using them, suggests that a
significant number of people disagree with this claim as well.
A
bit like driving a sports car over a traffic-calmed road - it can't go very
fast and a hatchback would make more sense, but if you own a sports car
already then you might want to do it.


So your contention is that C is a sensible language to use only on
platforms where it can be used in a dangerous mannner? Perhaps we
should take a little c.l.c poll. How many people here use C because
it lets you do unsafe things?

--
Michael Wojcik mi************@ microfocus.com

Not the author (with K.Ravichandran and T.Rick Fletcher) of "Mode specific
chemistry of HS + N{_2}O(n,1,0) using stimulated Raman excitation".
Nov 14 '05 #55

In article <c0**********@o ravannahka.hels inki.fi>, Joona I Palaste <pa*****@cc.hel sinki.fi> writes:

Could the distinction between a compiler and an interpreter be that when
they encounter program code, compilers translate it into another
language, while interpreters execute it? In other words, more or less,
compilers store away code for later execution while interpreters execute
it when they see it?


I'd call that a usable definition as well. We just recently had this
discussion in alt.folklore.co mputers, actually, with much debate about
where "tokenizing " BASIC implementations fit, for example.

I think this definition is largely parallel to the one I offered. An
interpreter could process an entire program as a unit, but it doesn't
need to; it's job, put simply, is "what do I do next?". A compiler
does something very different: it transforms some unit of source that
is in some way (as defined by the language) sufficiently syntactically
complete into a target form. What makes a compiler a compiler is not
that it targets any particular form, but that transforms a unit of
source data into a unit of target data (and since a compiler is not
an interpreter - though there are combined compiler-interpreters -
it probably stores the result for later use).

(In practice this definition would also have to note that by
convention "compiler" refers specifically to a tool in a software
build chain, so transformation tools for non-program data wouldn't
be included.)
--
Michael Wojcik mi************@ microfocus.com

Do not "test" parts, as this may compromise sensitive joinery. Those who
suffer difficulty should abandon the enterprise immediately. -- Chris Ware
Nov 14 '05 #56
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
nrk <ra*********@de vnull.verizon.n et> writes:
[...]
From "Advanced Compiler Design and Implementation" by Steven S. Muchnik:

<quote>
Strictly speaking, compilers are software systems that translate programs
written in higher-level languages into equivalent programs in object code
or machine language for execution on a computer.
...
The definition can be widened to include systems that translate from one
higher-level language to an indermediate-level form, etc.
</quote>

One might argue that an author/book cannot serve as an authoritative
definition of a term, but considering the widespread use and popularity of
the book, I would tend to take this to be an appropriate definition.


Doesn't IEEE have an official dictionary of computer terms? Can
someone who has a copy look up "compiler"?


I don't have access to their dictionary. But I think that most people
would agree that the compilation process consists in the translation from
a higher level language to a lower level language. I.e. if someone ever
manages to write a translator from binary executables to meaningful C
source code, no one would call this translator a compiler. Not even Aho
and his buddies ;-)

FWIW, the Dictionary of Computing edited by Oxford Science Publications
gives the following definition:

Compiler: a program that translates high-level language into absolute
code, or sometimes into assembly language. The input to the compiler
(the source code) is a description of an algorithm or program in
a problem-oriented language; its output (the object code) is an
equivalent description of the algorithm in a machine-oriented language.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #57
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.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #58
Malcolm wrote:
"Michael Wojcik" <mw*****@newsgu y.com> wrote in message

C programmers working on the AS/400 will find that expectation
[that pointer dereferences compile to single machine
instructions] is incorrect. In C on the AS/400, *nothing*
compiles to machine instructions, single or otherwise. It
compiles to a pseudoassembly language called "MI".

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.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #59

"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:

"Michael Wojcick
Etymology isn't meaning. The proverb is not used in that way.


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?
I was simply hoping to point out that you were employing a
bogus argument through an unfortunately popular turn of phrase,
apparently under the misapprehension that its common misuse made it
logically valid. Now it appears that you are simply unable to
understand that it's a bogus argument.
The exception proves (tests) the rule. The exception to the rule that C
compilers don't provide bounds checking is not really a compiler (we can
argue about exactly how to define "compiler", the AS/400 is in the penumbra
of meaning, but as someone who understands how language works thank you you
will have appreciated that). The exception is an oddball, the rule holds.
See "mammals are viviparous" for another example.
Because C sacrifices safety in memory access for efficiency.
Chapter and verse, please. (Oh, I realize this is standard C lore.
But the language does not *depend* on this trade-off, and it has
many admirable qualities which have nothing to do with it.)

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. However if
you already own a sports car you might not buy a hatchback for just one
journey.
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.
So your contention is that C is a sensible language to use only on
platforms where it can be used in a dangerous mannner? Perhaps we
should take a little c.l.c poll. How many people here use C because
it lets you do unsafe things?

How many people use C because it compiles to efficient machine code, and
tolerate the lack of safety because putting in bounds checking would
compromise speed?

Nov 14 '05 #60

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

Similar topics

12
4738
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
17552
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
9961
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...
1
10889
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
10441
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
9606
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
7993
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
7150
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();...
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3255
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.