Your posting has raised a lot of new points, but I really AM going
to stop, because I have little interest in C debates as such. I may
use the language, but have given up on hoping for improvement. My
Email address is real.
I don't have access to those discussions; all I can go by is what's
in the standard itself.
Some of them are online, but most of the C90 ones aren't. I threw out
my stack of paper a long time back. Unfortunately, the C standard is so
ambiguous and inconsistent that it isn't possible to decode what its
intent is from only the standard itself.
Let's not. By "after compilation" I meant "at run time". (I could
have been clearer; I wasn't even thinking about phase 8, i.e.,
linking.)
My error! Sorry. I am involved in too many standards, and had got
confused - I misremembered that phase 8 included execution, but it
doesn't. So, in my response, I meant "after compilation" by phase 8.
What I meant is that types are used by the compiler to resolve
the meanings of various program constructs and to constrain what's
valid and what isn't. They don't really exist in a running program.
By the time you have an executable, the type information, which is
internal to the compiler and/or linker, no longer really exists;
the same executable could have been generated from source in a
different language with a radically different type system.
I don't think the standard says this explicitly, but I think it's
a reasonable way of looking at it. I suppose it might also be
reasonable to think of types as existing in some abstract sense in
a running program. But I don't think that's entirely relevant to the
point I was making.
Yes, all of that's correct, except that they exist in more than an
abstract sense, via alignment and data validity. For example, whether a
malloced area includes a double or not is both dynamic and semantically
significant. As I said, C99 includes that explicitly (and differently)
via effective types.
When I wrote that the conversion "is conceptually a run-time
operation", I was being sloppy, and probably wrong. Most conversions
(such as casts) *are* run-time operations, though like any
other operation they can sometimes be resolved at compile time.
Regrettably, that is NOT true. Some are; some aren't; and some can
be either. That is not made clear in either 6.6 Constant expressions
or 6.5.4 Cast operators, but is implied by the need for consistency
with other parts of the standard.
The worst mess in this area is array adjustment, where the standard
doesn't specify WHERE in translation phase 7 it must occur, and where at
least one C90 compiler did it after type equivalencing and sizeof
evaluation etc. Despite WG14's view and the current consensus, that IS
a conforming implementation. I tried to get this fixed in both C90 and
C99, and failed dismally both times :-(
The standard uses the word "converted" to refer to what happens to
an array expression; I inferred from that that it's conceptually a
run-time operation. On further thought, I was likely wrong on this
point (which I consider to be a minor one); the array-to-pointer
conversion described in C99 6.3.2.1p3, and the function-to-pointer
conversion in p4, can only occur at compile time. (Which makes me
wonder if "converted" was the best word to use to describe it.)
Precisely.
I didn't say <string.h> is a counter-example.
Sorry.
An array value is the value of an array object. The definition of
"value" in C99 3.17:
precise meaning of the contents of an object when interpreted as
having a specific type
does not exclude array objects. Assignment of a struct containing an
array is a (rare) example of an array value being manipulated *at run
time* directly as a value, rather than indirectly via a pointer.
My point is that there IS no case where an array can be manipulated as
an object - and, no, that is not a counter-example. Regrettably, the
reasons why it isn't are very complicated, but are necessary to avoid
undefined behaviour when copying unions and in some other cases. You
can see some of them in 6.2.6.1 Representations of types, which states
(unclearly) that structure assignment is a 'byte copy' of some number
of bits and does NOT break down into an elementwise copy, though it
may be implemented like that (but need not be).
Again, I wasn't referring to phase 8. I'm saying that array values
exist *at run time*. Do you disagree?
Yes. They don't. Sorry. There is a strong sense in which C arrays
have a Pascal-like syntax and BCPL-like semantics. At run-time,
arrays ARE pointers, and strings ARE arrays. Well, I say that,
but the standard doesn't make it clear - however, as with array
adjustment, it is WG14's view and the consensus interpretation.
It becomes important to do with the interpretation of pointer
arithmetic, object access and restrict, in the presence of type
conversion of all sorts. I have a document that describes the problem,
which I have tried to get fixed many times, but with no success. If it
is NOT true, assigning to two different elements of the same array
object with no intervening sequence point becomes undefined behaviour.
And other problems.
I definitely think the are worth going into, and I urge you to do so.
The function reasons really aren't. They are ridiculously arcane,
and don't affect any current C programs, though they DO affect what
classes of extensions to the standard are possible.
Upthread you wrote:
In C, that is true. All of strings, arrays and (when used as
objects) functions are actually pointers, and it is important to
know and use that when passing them as function arguments.
There is a very common misconception that C arrays are really
pointers (see, for example, question 6.3 of the comp.lang.c
FAQ, <
http://www.c-faq.com/>). I took your statement to be a
confirmation of that misconception. I don't believe you actually
have that particular misunderstanding, but if you'll re-read what
you wrote, I think you might find that your statement might tend
to reinforce the false idea that C arrays are really pointers.
Probably I misunderstood what you meant.
I am afraid not. That isn't a misconception - it is one of the numerous
errors in the C FAQ. I haven't looked at it in over a decade but, when
I did, over half of then entries I looked at were seriously misleading
or erroneous.
You might also like to look at C1X (n1339 6.5.1.1 Generic selection)
and consider the consequences of that not being so
I accept that it is also misleading to state that C arrays are simply
pointers, because they are NOT pointers as far as most declarators and
type management go. But there it ends - semantically, they are just
pointers.
Regards,
Nick Maclaren.