J
Joshua Maurice
This is a pretty interesting claim. How does it mesh with your understanding
of the phrase "to define a word"? How about "to define an inline function"?
I cover that in that same post, further down. You also directly
replied to it. See there.
7.17 Common definitions <stddef.h>
The following types and macros are defined in the standard
header <stddef.h>.
The *types* are *defined*.
Please see: 6.2.1 Scope of Identifiers / 5. (I refers to section 6
instead of 5 in the previous post.) It specifically says when the
standard talks about an identifier X, they really mean to talk about
the thing to which the identifier refers, unless otherwise explicitly
stated. So, under that reading, types are defined.
However, I point you to "7.17 Common definitions <stddef.h> / 4",
which says that the recommended practice is to define size_t with a
typedef. So, when the standard says "The following types and macros
are defined in the standard header <stddef.h>", the standard writers
explicitly stated that the recommended way to "define" those types was
with typedef.
Next, "6.7.7 Type definitions / 3" says that "A typedef declaration
does not introduce a new type, only a synonym for the type so
specified". So, that means that the recommended practice is that
size_t is only a synonym for another "basic" type, and not a new
type.
Thus I posit that "The following types and macros are defined in the
standard header" is simply shorthand or an oversight for "the
following type /names/ and macros are defined in the standard
header".
If there were, there would be a crucial distinction to be drawn between
"defining a type" and "defining a type name". But there isn't. So there
isn't. What's left is to observe the consistent usage of phrases
such as "types ... are defined" to refer to the definition of type-names.
Did you read 6.2.1 Scope of Identifiers / 5. It very clearly calls out
that there is a difference between the nam and the thing to which the
name refers.
Given:
extern signed long sl;
extern signed short ss;
and assuming that both objects hold values which are not trap
representations, consider:
ss = sl; /* may be undefined behavior */
sl = ss; /* is not undefined behavior */
This has absolutely nothing to do with type safety. Do you even know
what a type system is?
No, it isn't.
I am not convinced that we can draw this conclusion. We certainly know
they're compatible. We know that types which are the same type are
compatible. However, this does not mean that there is no other way that
two types could be compatible.
True. See
6.2.7 Compatible type and composite type / 1
It has an attached note.
46) Two types need not be identical to be compatible.
However, it appears that only obscure scenarios allow for distinct
types to be compatible. See
6.2.7 Compatible type and composite type / 3
and
6.2.7 Compatible type and composite type / 5
Neither "struct foo" and "bar" are type "void", so they must be the
same type. There is no other explanation.
Wait a minute. Here's a fun one.
int main()
{
typedef void my_void;
my_void * x;
int * y = x;
}
This is well formed code. It compiles. There is a specific allowance
that says a type of "void pointer" can be assigned to any pointer
type. How the hell do you explain why this is well formed code without
acknowleding that "my_void" is the type "void", then applying the
"void pointer" allowance to convert it to "int pointer"?
I don't think so, simply because the common English meaning of the word
"define" is unambiguously "sane". To give a definition of; not to create.
It's not different from the sense in which I would usually talk about
defining a type.
Well, you will sometimes. Or perhaps it's two words which happen to be
written the same.
But something else could define a different word to be the same thing.
colour, n.: Alternative spelling of color.
Behold! It is a definition. It does not create a word. It does not
"redefine" another word. And yet, it defines one word to be the same
as another.
It depends on your particular definition of "create". Generally
programmers say that they "create" types when they write "struct foo
{ int x; };". I don't want to discuss Platonic ideals or anything
else. That's just the way it is.
You really are inventing definitions now. It doesn't "redefine"
another word. "To redefine" means to take something which already has
a definition, toss out that old definition, and give it a new one.
There is no ambiguity there.
Finally, this disputes nothing which I've said. I've said that when a
word is defined in a dictionary, it happens only once. You will only
ever find one entry for any particular word. This is no way rules out
homonyms.
To sum this all up, I have yet to see any contradictory usage of the
terms from reliable text, such as a programming language definition, a
paper written by a programming language expert, etc.
I suppose people who were involved with writing the standard are not
technically "experts", true.
But I've given many examples of contradictory usage in the standard itself.
In particular, the standard seems quite clear and consistent in treating
"typedef name" and "type" as essentially interchangeable while discussing
the behavior of the standard headers. Types and macros are defined
in <stddef.h>. We are told that <stdint.h> "declares sets of integer types",
and then we see "... <stdint.h> shall declare that typedef name and
define the associated macros." In 7.18.1.1, we see:
The typedef name intN_t ...
[...]
These types are optional.
In 7.18.1.2, after introducing "the typedef name int_leastN_t", the standard
goes on to say "The following types are required:", and lists typedef names.
In short, the standard is quite consistent about not being consistent in
this; the terms are repeatedly treated as functionally interchangeable.
It is a lack of consistency in word choice, but not an inconsistency
in the definitions and terms. Most of that isn't as bad as you make it
out to be. Remember that every definition is a declaration, so they
can say "declare" if it's a "definition". It's logically valid.
Also, due to the lack of perfection of the standard, this is why I
invoked other standards, other papers, and so on, besides just relying
on a single document made by man. Yet you immediately attack me about
talking about the C++ standard (just below). Thus you can have your
cake and eat it too, and apparently be the sole arbiter on the meaning
of words in programming.
This is completely irrelevant; the C++ standard and the C standard disagree
on a great deal of terminology.
Only you haven't. You've repeatedly asserted it, but you have yet to
demonstrate that the alternative model I use is incorrect or contradicts
the standard any worse than yours does. (Both contradict at least some
of the text, since the text itself is pretty much agnostic on the issue.)
If we start with the clear language in the standard governing "defining
typedef names" (which is clearly and unambiguously correct), and combine it
with the general disregard for any hypothesized distinction between typedef
names and types, we find that it is perfectly reasonable to refer
to typedef as "defining types", because the language spec does not
consistently distinguish between typedef names and types.
So far as I can tell, the standard has two modes of discussion of this. One
is the sense in which a distinction is being drawn between creating a new
type and merely creating a synonym for it, and in this context, we find
that typedef is merely defining "typedef names". The other is the sense
in which we are not talking about the underlying mechanics, but the effect
on a program, and the way a programmer interacts with type names; in this
sense, we find that "defines an identifier to be a typedef name" and "defines
a type" are functionally interchangeable.
In short, if you just want to write code, you can refer to typedef as
defining types, and nothing will go wrong. If you want to write a compiler,
there will be an afternoon or so during which you need to distinguish between
"new types" and "new typedef names", after which it stops mattering again.
Now, it's entirely possible that you know a great deal more about the standard
than the people who wrote it, and that we were all fools to refer to headers
as defining types, but it seems more reasonable to me to just assume that we
used that wording because it was clear, unambiguous, and communicated
correctly what it needed to communicate.
What is the meaning of define a type in your world? In my world, "to
define a type" means to create a new type which is distinct from all
other types according to the type system. Do you believe that "declare
a type name", "define a type name", "declare a type", "define a type",
and "define a new type" are all equivalent?