--- In [email protected], "Tyler Littlefield" <ty...@...> wrote:
>
> so here's the question. Whose buying it for me? <wink>
:-)
Last week a bug was discovered in the code I work on (not in my area).
Some of our message types use anonymous unions, which have the
interesting property that 2 fields at different offsets within a
structure and even of different types can have the same name. The bug
was similar to:
struct {
union { int i; int c; }; /* first c */
union { char c; }; /* second c */
} s;
int main(void) {
s.c = 'X'; /* Bug!! Assigned to int c, should be char c */
return 0;
}
This compiles with no warnings under gcc using -Wall to enable 'all'
warnings. PC-Lint first warns that you are using anonymous unions,
then points out that the reference to s.c is (logically) ambiguous.
Unfortunately PC-Lint wasn't being used. I don't know how long it took
to spot and how many test engineers were involved in trying to find
it, but it doesn't take many engineer hours to exceed the price of one
copy of PC-Lint.