PC-lint/FlexeLint Output | Reference Manual Explanation | Home

            bug1503.cpp

1     #include <stdio.h>
2
3     int n;
4     struct A
5         {
6         union anonymous
7             { double x; int n; char ch; };
8         int k;
9         A() { k = 1; n = 2; }
10        int f() const { return n; }
11        } a;
12
13    int main()
14        {
15        n = 34;
16        printf( "%d\n", a.f() );
17        return 0;
18        }

The programmer expected the function A::f() to return the value 2. Instead some other value was printed. What's the mistake?


bug1503.cpp lint Output

--- Module:   bug1503.cpp
                                     _
        { double x; int n; char ch; };
bug1503.cpp(7) : Warning 1503: a tagged union is not anonymous

    --- Wrap-up for Module: bug1503.cpp

Info 754: local structure member 'anonymous::x' (line 7, file bug1503.cpp) not
    referenced
Info 754: local structure member 'anonymous::n' (line 7, file bug1503.cpp) not
    referenced
Info 754: local structure member 'anonymous::ch' (line 7, file bug1503.cpp) not
    referenced

Reference Manual Explanation


1503  a tagged union is not anonymous   -- A tagged union without a declarator appeared
      within a struct/union declaration. An anonymous union requires no tag.   [11 section 9.5]

If you have comments or questions about this bug, please post them to our   Discussion Forum

Previous Bug - Bug #561 - August 2003

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software