csk@Ucla-Security@sri-unix (09/18/82)
From: csk at Ucla-Security (Charley Kline) Date: 15 September 1982 1344-PDT (Wednesday) (I sent this message earlier, but it never showed up!) There have been several messages to this group about this or that Portable C Compiler (PCC) bug/feature. Having just about finished a PCC port for a strange machine, I thought I should point out that PCC (at least the versions I have seen) contains numerous bugs, and that one For example, the following program fails on the PDP11 PCC (both V7 and System 3): main() { struct { int a[4097]; int x; } foo; int i; unsigned j; i = foo.x; j = ( (unsigned) i) >> 1; } First, the address calculation for foo.x is not handled correctly because offsets to fields inside the compiler are kept as bit offsets in an integer (which is only 16 bits on the PDP11), resulting in overflow for a[4097]. In fact, if the line had read a[4096] you get a error illegal zero length field since 4096*16 is zero in a 16 bit word! Second, the shift of i is performed signed rather than unsigned (arithmetic shift rather than a logical shift)! This occurs because the compiler attempts to be clever and eliminate unneeded conversions, and decides that converting an int to an unsigned is unnecessary (which is true) but forgets to relabel the internal tree so that the item is considered as unsigned. This bug is in every PCC I have seen (including the VAX C comon the VAX because of the way shift code is generated). My point here is not to complain about PCC, which is actually a rather nice, clever, simple compiler, but rather to point out that the PDP11 one is fairly buggy (probably due to the fact that the Richie compiler generated better code and thus, PCC was not heavily used), and that one must be very careful in using it as the basis for ports. One of the previous messages to this group implied that Johnson had an improved PC --charley