RAD Studio |  |

Structure Name Spaces

Structure tag names share the same name space with union tags and enumeration tags (but enums within a structure are in a different name space in C++). This means that such tags must be uniquely named within the same scope. However, tag names need not differ from identifiers in the other three name spaces: the label name space, the member name space(s), and the single name space (which consists of variables, functions, typedef names, and enumerators).

Member names within a given structure or union must be unique, but they can share the names of members in other structures or unions. For example

Copy Code

    goto s;
        .
        .
        .
    s:           // Label
    struct s {   // OK: tag and label name spaces different
       int s;    // OK: label, tag and member name spaces different
       float s;  // ILLEGAL: member name duplicated
    } s;         // OK: var name space different. In C++, this can only
                 // be done if s does not have a constructor.
    union s {    // ILLEGAL: tag space duplicate
       int s;    // OK: new member space
       float f;
    } f;         // OK: var name space
    struct t {
       int s;    // OK: different member space
        .
        .
        .
    } s;         // ILLEGAL: var name duplicate

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!