C strongly typed?

Charles Hannum CMH117 at psuvm.psu.edu
Sun Mar 11 18:41:13 AEST 1990


In article <1798 at gannet.cl.cam.ac.uk>, nmm at cl.cam.ac.uk (Nick Maclaren) says:
>
>The ANSI standard (and K&R) explicitly require that any data type may be
>treated as an array of characters ...
>the above).

This is simply not true!  See below ...


>             A huge proportion of the library relies upon this to work at
>all (e.g. much of string.h, some of stdlib.h, some of stdio.h).

Well, everything in string.h works with arrays of characters; what's your
point?  As for stdlib.h and stdio.h, see comments on the void type below ...


>    union {void *a; char *b;} fred;
>    fred.a = ...;
>    ... = fred.b;

What is wrong with this?  First, this would only work if "..." was another
void pointer or a char pointer.  You seem to be bashing C for the inclusion
of a void type ...

"void" in C is similar to "nil" in LISP.  It's just a generic type, which can
hold the place of any other type, WHEN USED IN A POINTER!!  I couldn't assign
a character to a void type, for example.  But I *can* assign a void pointer
to a character pointer, and vice versa.  This is part of the power of the C
language.  It simplifies things like malloc(), for example.

And void has *nothing* to do with char!  Try this:

  #include <stdio.h>

  int main(void) {
      printf("%d %d\n",sizeof(void),sizeof(char));
  }


(Actually, my code sample above *does* show a deficiency in the C language;
 let's see if anyone can figure out what it is.)


>[rest of gibberish deleted]

Personally, I'm more concerned about the fact that this stupid terminal's "0"
key on the keypad isn't working.  It causes a lot more problems than a void
type.


Virtually,
- Charles Martin Hannum II       "Klein bottle for sale ... inquire within."
    (That's Charles to you!)     "To life immortal!"
  cmh117 at psuvm.{bitnet,psu.edu}  "No noozzzz izzz netzzzsnoozzzzz..."
  c9h at psuecl.{bitnet,psu.edu}    "Mem'ry, all alone in the moonlight ..."



More information about the Comp.lang.c mailing list