Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site ubc-cs.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!alberta!ubc-vision!ubc-cs!ludemann
From: ludemann@ubc-cs.UUCP (Peter Ludemann)
Newsgroups: net.lang.c
Subject: Re: how has C bitten you?
Message-ID: <1223@ubc-cs.UUCP>
Date: Sun, 18-Aug-85 15:20:24 EDT
Article-I.D.: ubc-cs.1223
Posted: Sun Aug 18 15:20:24 1985
Date-Received: Fri, 23-Aug-85 23:47:17 EDT
References: <4051@alice.UUCP> <2600011@ccvaxa> <399@ucsfcca.UUCP>
Reply-To: ludemann@ubc-cs.UUCP (Peter Ludemann)
Organization: UBC Department of Computer Science, Vancouver, B.C., Canada
Lines: 42
Keywords: type checking, structures, C standard

Here's my favourite bite in the neck (apologies if I've made
any typos - this is just an example):

typedef union {
		int  u1;
		char u2;
	} union_type;

typedef struct {
		int        f1;
		union_type f2;
	} struct_type;

struct_type s;

s.u1 = 0;   /* should be: s.f1.u1 = 0 */

This has the effect of "s.f1 = 0" with no complaint from
the compiler (lint, of course, is another matter).  Truly
spectacular results can occur if "f1" is a pointer to
another area.

The really annoying thing is that K&R (page 186) says:
    A primary expression followed by a dot followed by an
    identifier is an expression.  The first expression must
    be an lvalue naming a structure or union, and the 
    identifier must name a member of the structure or union.
In other words, type checking almost as strong as Pascal's (yes,
I know about the case where two structures have the first fields
declared the same).

However, K&R (page 209) says "... this restriction is not
firmly enforced by the compiler."  It is sad that the defects
of the original C compiler have been slavishly copied by
subsequent ims.  If backward compatibility were
important a "don't check structures strictly" switch could
have been added to the compilers.
-- 
ludemann%ubc-vision@ubc-cs.uucp (ubc-cs!ludemann@ubc-vision.uucp)
ludemann@cs.ubc.cdn
ludemann@ubc-cs.csnet
Peter_Ludemann@UBC.mailnet