Simple question about pointer types

B

Bart van Ingen Schenau

There would be no need for a char* to be able to point into the code
space (unless the compiler supports meaningful conversions between
char* and function pointers as an extension). Pointing into the
register space could be useful, of course (but again it's probably not
required for C semantics).

The names 'code space' and 'data space' are not quite accurate.
As far as the compiler is concerned, all ROM is in the 'code space'
and all (volatile) RAM is in the 'data space'. The compilers for the
8051 CPU allow one to store constant data in the 'code space', so it
is meaningful to have data pointers that point into the code space.

Bart v Ingen Schenau
 
K

Kevin Bagust

There would be no need for a char* to be able to point into the code space
(unless the compiler supports meaningful conversions between char* and
function pointers as an extension). Pointing into the register space
could be useful, of course (but again it's probably not required for C
semantics).

If it is the same compiler I am using for the 8051 (Keil compiler) it is
easyer to think of them as pointers to RAM, ROM and registers. So you want
to be able to use pointers to code space for constants, for two resons.

You do not have space in the RAM for copies of the constants, and you do
not have the time at start up to copy all the constants into RAM.
Out of curiosity, was this extended pointer format implemented in hardware
or in software? I know it doesn't matter as far as the C language is
concerned, but it would be nice to have more ammunition against the
assumption that a C pointer is always a hardware address.

It is done in the software as functions which are called whenever you
reference a pointer. Which is why on this complier you should try and
aviod generic pointers.

Kevin Bagust.
 
K

Kenny McCormack

In other words,

In my limited experience, which doesn't even go back as far as
MS-DOS, and is therefore hardly a guarantee in the real world.

You got it.
The point, of course, is that with suitable qualifiers, any statement can
be made to be true.
How about the entire sentence?

Thank you for proving my point.
 
M

Michael Wojcik

but it would be nice to have more ammunition
against the assumption that a C pointer is always a hardware address.

There's always the good ol' AS/400.

For anyone who's missed this discussion in the past: On the 400,
hardware addresses are 64 bits but C pointers are 128 bits. (In the
versions I've worked with, the largest integer types were 32-bit; I
think 64-bit integers are available now, but you still can't cram a
pointer into any sort of integer type.) Of course, like other
application programming languages on the 400 (as opposed to those
used to write the 400's Licensed Internal Code), C is compiled to the
MI pseudo-assembly language, which also uses the 128-bit "addresses".
The translation to 64-bit hardware addresses happens lower down.

(This doesn't apply to the 400's PASE environment, which gives
processes a more traditional private 64-bit address space, rather
than letting them play in the 128-bit "single-level store" shared
address space. Or so I've heard.)

--
Michael Wojcik (e-mail address removed)

She felt increasingly (vision or nightmare?) that, though people are
important, the relations between them are not, and that in particular
too much fuss has been made over marriage; centuries of carnal
embracement, yet man is no nearer to understanding man. -- E M Forster
 
R

Richard Bos

You got it.
The point, of course, is that with suitable qualifiers, any statement can
be made to be true.

So. You didn't have any real information, you just wanted to be contrary
for the sake of it. Glad to have cleared that up.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top