473,889 Members | 1,443 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 125291

In article <c0**********@n ews5.svr.pol.co .uk>, "Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
In fact a non-perverse use of pointers would be to store the bounds of the
data item pointed to in every pointer. Then an attempt to address memeory
illegally could be caught. To my knowledge not a single implemetation
actually uses safe pointers.
Your knowledge is incomplete. At least three C implementations for the
AS/400 - EPM C, System C, and ILE C - use 16-byte / 128-bit pointers
(CHAR_BIT is 8) which are not simple addresses but descriptors, and
which include a reference to a memory space, an offset in that memory
space, and a validity flag which can only be set by a privileged-mode
instruction. Mucking about with a pointer's internals resets the
flag, rendering the pointer invalid.

All three implementations will immediately trap on invalid pointer
access.

I believe ILE C (the current one) is a fully conforming C94 hosted
implementation, and System C was a fully conforming C90 hosted
implementation. I suspect EPM C wasn't a conforming hosted
implementation, though it probably came fairly close, and may have
been a conforming freestanding implementation.
The reason of course is that C programmers
expect pointer dereferences to compile to single machine instructions -
something again not mentioned in the standard but highly relevant to anyone
who programs in C.


C programmers working on the AS/400 will find that expectation is
incorrect. In C on the AS/400, *nothing* compiles to machine
instructions, single or otherwise. It compiles to a pseudoassembly
language called "MI". And that's a good thing, for AS/400 software,
since it's one of the qualities that allowed IBM to completely change
the machine's architecture without breaking working programs. (That's
*binaries*, with no recompilation required, in many cases.)

On the AS/400, robustness trumps performance. That was the design
decision for the whole architecture, and C needed to fall in line.
One of the nice things about the C standard was that it could
accomodate that.

More C programmers should do some work on the AS/400. (For one thing,
it'd make them appreciate their other development environments all
the more, if they use IBM's awful Program Development Manager and
Source Entry Utility.) You can learn a lot about what a conforming
hosted implementation can do. And if you're using a real 5250
terminal, you can also learn those swell trigraph sequences (or the
EBCDIC code points for various C punctuation characters).
--
Michael Wojcik mi************@ microfocus.com

Pseudoscientifi c Nonsense Quote o' the Day:
From the scientific standpoint, until these energies are directly
sensed by the evolving perceptions of the individual, via the right
brain, inner-conscious, intuitive faculties, scientists will never
grasp the true workings of the universe's ubiquitous computer system.
-- Noel Huntley
Nov 14 '05 #31

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

In article <news:c0******* ***@newsg4.svr. pol.co.uk>
Malcolm <ma*****@55bank .freeserve.co.u k> writes: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.


But if you believe that C on this machine is not "compiled", then
you must believe that *nothing* on the AS/400 is *ever* compiled --
not COBOL, not RPG, not Modula-2. Yet IBM will sell you "compilers"
for all of these, as well as for C and C++. There are even AS/400
assemblers that read "MI" source and produces "machine code":
<http://www-1.ibm.com/servers/eserver/iseries/whpapr/translator.html >.

Would you also claim that any machine on which the machine's "opcodes"
are interpreted by microcode has no compilers? If not, why do you
distinguish between OMI opcodes and microcoded-machine opcodes?
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.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 #33
"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
"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.


Exceptions don't prove points, as least not in the sense you mean.

There are plenty of compilers that generate something other than
machine code. I'm not familiar with the AS/400, but I haven't seen
anything to suggest that C is a poor language for it.

--
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 #34
Keith Thompson wrote:

"Malcolm" <ma*****@55bank .freeserve.co.u k> writes:
This really is the exception that proves the point.


If you ever see me using sophistry like that, here,
it will be the first of April.
Exceptions don't prove points, as least not in the sense you mean.


--
pete
Nov 14 '05 #35
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
machine code. I'm not familiar with the AS/400, but I haven't seen
anything to suggest that C is a poor language for it.


It depends on how you define the notion of poor language.

It is a fact that C is not the language of choice for the primary
application domain of this machine (small business server) and that very
little (if any) of the open source C code available on the Internet
has been ported to that platform (or written with portability to this
platform in mind).

It is possible to program in C on this machine, but apparently few of
those who did it actually enjoyed the experience. And this has precious
little to do with the unusual pointer size/representation.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #36

"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? If not,
why do you distinguish between OMI opcodes and microcoded-
machine opcodes?

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?

Microcode creates a grey area. 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. Of course a really good optimising C compiler should build
and load microcode itself :-).

Ultimately it's just a question of definition - how far can we extend the
term "compiler" until we're talking about two totally different things? The
AS/400 almost certainly contains a substantial amount of C code which is
compiled to native machine code and runs the OS. How are we to distiguish
this compiler from the "compiler" shipped to customers?
Nov 14 '05 #37

"pete" <pf*****@mindsp ring.com> wrote in message
This really is the exception that proves the point.


If you ever see me using sophistry like that, here,
it will be the first of April.
Exceptions don't prove points, as least not in the sense you mean.

"The exception proves the rule" is a famous proverb. "Prove" means "tests",
not "demonstrat es the point".

Now I claimed that not a single compiler, to my knowledge, implemented safe
pointers. An exception was raised. 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". So the exception
actually demonstrates that the point is valid.
Nov 14 '05 #38

In article <c0********@ene ws2.newsguy.com >, Chris Torek <no****@torek.n et> writes:

But if you believe that C on this machine is not "compiled", then
you must believe that *nothing* on the AS/400 is *ever* compiled --
not COBOL, not RPG, not Modula-2. Yet IBM will sell you "compilers"
for all of these, as well as for C and C++.
Indeed, though I suppose we shouldn't in general allow IBM to define
"compiler" for us. Still, I think the consensus among AS/400
programmers is that we are, indeed, compiling our programs, and I
defy Malcolm to prove otherwise.
There are even AS/400
assemblers that read "MI" source and produces "machine code":
<http://www-1.ibm.com/servers/eserver/iseries/whpapr/translator.html >.


In fact, there used to be (and probably still is) a C API supplied by
IBM for this purpose; IIRC, it was just a function that took a
FILE* referring to a file open for writing and a string containing
MI source, assembled the latter, and wrote it into the former. Which
made the AS/400 the easiest machine I knew of to write an assembler
for...

(MI is a nicely CISCy pseudo-assembly, with opcodes like "translate
byte using table". Not as CISCy as VAX assembly, as I recall, but
pretty rich.)

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

This record comes with a coupon that wins you a trip around the world.
-- Pizzicato Five
Nov 14 '05 #39

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

"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.
That's not what that idiom means. "The exception proves the rule"
is a partial vernacular translation of a Latin legal principle which
means that when an exception is explicit in the law ("No parking
between 9AM and 5PM"), it implies a general rule where the exception
does not apply ("You may park between 5PM and 9AM").

In what logical system does the existence of an exception prove that
the general thesis is true? In fact, what we have here is an
exception which disproves the thesis. See [1].
A platform that
disallows native machine langauge programs cannot really be said to have a
compiler.
Oh yes it can. Observe: There are compiled languages on the AS/400.
Perhaps you need to review what a "compiler" is. Hint: it's not a
system for translating some source language into "native machine
language". That's why Java, for example, is still a compiled
language.

A compiler *compiles*. It collects multiple source statements and
processes them as a whole into some form more amenable for execution.
Contrast that with an interpreter, which is incremental - it processes
and executes one "statement" (however defined by the language) at a
time.

In any case, the C standard says nothing about compilation. There is
an implementation, which acts upon translation units. A program is
composed of one or more translation units, which undergo the various
translation stages specified by the standard.
Nor is C the ideal language for such an environment - you need
something which does memory management for you.


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?
1. http://alt-usage-english.org/excerpts/fxtheexc.html

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

Is it any wonder the world's gone insane, with information come to be
the only real medium of exchange? -- Thomas Pynchon
Nov 14 '05 #40

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
9805
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
11188
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...
0
10785
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10887
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
5825
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4644
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
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3253
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.