Phil Carmody said:
we're not.
did you miss the "in ..." clauses nearby the word "address" above?
I'll try to make my point again without being quite so dismissive.
See above. Addresses are addresses. They are defined by the hardware,
your silly C language pretends to model them closeley, and often
suceeds. As bit-strings (not necessarily atomic), they are integers.
I'm a bit surprised that you have an embedded background given your
above "everything revolves around C" attitude.
The fact that something is represented as a bit-string does not imply
that it's an integer. In computer systems, bit-strings are used to
represent everything that can be represented. Yes, addresses are
represented as bit-strings; so are floating-point numbers.
There is a mapping between addresses and integers, exposed in C by the
semantics of pointer-to-integer and integer-to-pointer conversions.
On many systems, that mapping is trivial. On others it may not be.
If you're talking about a particular low-level system, outside the
context of C, it may well be reasonable to treat addresses as integers.
That doesn't mean that addresses *are* integers, and it certainly
doesn't mean that addresses are ints (where "int" is a specific type
that exists in C).
A side point: it's quite common for addresses and "int" to have
different sizes.
You can add, multiply, divide two integers and get a meaningful
result. You can't do that with two addresses.
let's comapare an contrast:
char foo[10]={/*whatever*/};
int index = 7;
index *= index; // KT approved, it's an int!
The result of the multiplication is well defined (it's 49, obviously).
If "index" were a pointer, that operation would be about as meaningful
as the square root of beige.
bar(foo[index]); // no regrets
I'm sure misusing an integer value as an out-of-bounds array index makes
some point, but I don't know what it is.
I can imagine cases where the result of an integer multiplication could
sensibly be used as an array index.
against:
const u32 FIFO1_LWM_INT = 0xC0084001; // address of hw register
const u32 FIFO1_HWM_INT = 0xC0084002; // address of hw register
u32 whocareswhat= FIFO1_LWM_INT*FIFO1_HWM_INT;
which is the more bogus code?
I presume u32 is an unsigned 32-bit integer type. If so, the result of
the multiplication is well defined by C, but if the operands are integer
representations of memory addresses it's probably not meaningful.
In C terms, 0xC0084001 is not an address. It may well be the result of
converting an address to u32, and converting 0xC0084001 to some pointer
type would yield an address. And one can certainly informally talk
about, say, "the address 0xC0084001" -- assuming that makes sense for
the particular system being discussed.
I know you'ved approved the former,, and think that the latter is inherently
evil, but I would ask you to reconsider.
I would ask you to reconsider putting words in my mouth. In particular,
I've said that multiplying two addresses is meaningless, and that
addresses are not integers (in C, of course); I don't know how an
example of multiplying two integers is relevant to that.
To summarize:
In C, addresses (i.e., values of pointer type) are distinct from
integers. They can be converted back and forth; the result of such a
conversion is "intended to be consistent with the addressing structure
of the execution environment", whatever that may be. Very commonly this
makes the conversion trivial, just reintrepreting the bits.
In contexts other than C, it may well make sense to treat addresses and
integers as the same thing, or as very similar things. An address might
logically be an integer index into an "array" that corresponds to the
machine's entire (virtual or physical) memory. Or it might be something
else altogether; it depends on the system.
Since this is a C newsgroup, it is my opinion that it's a good idea to
make the distinction between integers and addresses clear. Among other
things, it might prevent inexperienced C programmers from wondering why
void *ptr = 0xC0084001;
is rejected.
I'm aware that a lot of this is stuff that you know as well as I do.
I'm restating some of it in the hope of figuring out just where we
disagree.
Do you disagree with any of that?