how has C bitten you?

M. Cain michael at python.UUCP
Fri Aug 16 23:26:09 AEST 1985


This one didn't bite me directly, but my wife spent most of a day
finding a more complicated instance of it in someone else's code.

Start with two source files:
foo.c:
main()
{
    sub2(1);
}

sub1()
{
}

bar.c:
extern sub1(a,b);

sub2(x)
int x;
{
    printf("a = %d, b = %d, x = %d\n",a,b,x);
}

Compiling with "cc foo.c bar.c" produced no error messages at all.
But when a.out is executed, the output was

a = 1, b = junk, x = junk

This was all done under XENIX on a Sritek 68000 board.  Same kind
of screw-up in both AT&T and Berkeley universes on a Pyramid.  Lint
on the Pyramid complains that sub2() has a variable number of argu-
ments.  Two different 68000 cross-compilers make the same mistake.
Our VAX running System V correctly tagged the extern statement as
incorrect.  My 6809 OS-9 system missed the extern statement, but at
least pointed out that a and b are undefined within sub2().

Michael Cain
Bell Communications Research
..!bellcore!python!michael



More information about the Comp.lang.c mailing list