C
Chris Torek
No, the "void" type itself (but not "void *") appeared some time
around 1979 or so, about the same time as PWB-Unix and Steve
Johnson's Portable C Compiler. ("void" and "enum" appeared about
the same time. PCC also introduced separated struct/enum namespaces
-- you could now write:
struct A { int a; int b; };
struct B { int b; int a; };
which in Dennis Ritchie's older compilers was invalid; all "struct"
members were in a single namespace, so each had to have a unique
name. This is at least part of the reason that Unix-y "struct"s
use per-struct member prefixes, e.g., "tm_year" inside a "struct
tm", or "st_dev" inside a "struct stat" -- not just "year" and
"dev". PCC had a backwards-compatiblility hack: if X was any
lvalue, or P was a pointer with structure type S, and you wrote
X.field or P->field, and "field" was not a member of the structure
S, PCC would search all the other "struct" and "union" types for
the first one with a member named "field", use that field's type
and offset, and emit a warning. Among other things, this meant
you could write:
struct { char lo, hi; };
short s;
...
s = some_expression();
printf("as word: %o; as bytes: %o, %o\n", s, s.lo, s.hi);
and the old "adb" program used this very construct. Yes, it
sign-extended the bytes, which I found quite annoying. Of course,
Dennis' original compilers did not have "unsigned char" either --
PCC added unsigned variants of all the integral types. Indeed,
early C had no "unsigned" keyword at all; if you wanted unsigned
integers, you declared pointers!)
The "void *" type was an ANSI-committee invention, though.
This is not quite right either. The original ANSI C standard came
out in December 1989, yes, but Stroustrup's C++ book was out well
before that -- I believe I read it in 1986, and apparently it was
published in 1985. Of course, that particular C++ was a very
different language from today's C++.
around 1979 or so, about the same time as PWB-Unix and Steve
Johnson's Portable C Compiler. ("void" and "enum" appeared about
the same time. PCC also introduced separated struct/enum namespaces
-- you could now write:
struct A { int a; int b; };
struct B { int b; int a; };
which in Dennis Ritchie's older compilers was invalid; all "struct"
members were in a single namespace, so each had to have a unique
name. This is at least part of the reason that Unix-y "struct"s
use per-struct member prefixes, e.g., "tm_year" inside a "struct
tm", or "st_dev" inside a "struct stat" -- not just "year" and
"dev". PCC had a backwards-compatiblility hack: if X was any
lvalue, or P was a pointer with structure type S, and you wrote
X.field or P->field, and "field" was not a member of the structure
S, PCC would search all the other "struct" and "union" types for
the first one with a member named "field", use that field's type
and offset, and emit a warning. Among other things, this meant
you could write:
struct { char lo, hi; };
short s;
...
s = some_expression();
printf("as word: %o; as bytes: %o, %o\n", s, s.lo, s.hi);
and the old "adb" program used this very construct. Yes, it
sign-extended the bytes, which I found quite annoying. Of course,
Dennis' original compilers did not have "unsigned char" either --
PCC added unsigned variants of all the integral types. Indeed,
early C had no "unsigned" keyword at all; if you wanted unsigned
integers, you declared pointers!)
The "void *" type was an ANSI-committee invention, though.
It was defined in the first ANSI-C (as opposed to old-style K&R) I used.
That was in '89. C++ was nowhere in sight. Yet.
This is not quite right either. The original ANSI C standard came
out in December 1989, yes, but Stroustrup's C++ book was out well
before that -- I believe I read it in 1986, and apparently it was
published in 1985. Of course, that particular C++ was a very
different language from today's C++.