C strongly typed?

merriman at ccavax.camb.com merriman at ccavax.camb.com
Fri Mar 9 07:50:07 AEST 1990


In article <1990Mar7.182230.5517 at utzoo.uucp>, henry at utzoo.uucp (Henry Spencer) writes:
> However, if you write something like:
> 
> 	char *p;
> 	int a;
> 	...
> 	a = p;
> 
> any modern compiler will object.  C's type system is not extensible unless
> you count "struct", but the language is strongly typed -- mixing random
> types is not allowed.

I guess that lets VAX C out as a modern compiler. the following compiles
without complaint:

#include stdio

int i;
char c;
int *ip;
char *cp;

main()

{
i = 700;
c = i;

printf("%d %d\n", i, c);

ip = &i;

cp = ip;

printf("%d %d\n", *cp, *ip);

i = cp;

ip = i;

printf("%d %d\n", *cp, *ip);

}

and produces the following output:

700 -68
-68 700
32 544

Anyone care to explain the last line of output?

BTW, I included the int to char assignment to demonstrate what I consider
to be a really obnoxious and dangerous shortcoming (at least in VAX C).
Do real C compilers allow the same thing, without comment?



More information about the Comp.lang.c mailing list