Error related to Structure or Union

Discussion in 'C Programming' started by the_init, Mar 22, 2007.

  1. the_init

    the_init Guest

    Hi friends,

    OS: Netware
    Compiler: Watcom 11.0

    I am using athe following structure in my program. But when I compile
    it is giving
    Error: E1172 Expected struct or union tag but found 0x08 at line 10.
    i.e. where I have declared the structure.
    I also searched in google but didn't find any related answer. Please
    help me.

    Line 10: struct _SHOW
    {
    unsigned char OC;
    unsigned char Reserved : 5;
    unsigned char DeviceNumber : 3;
    unsigned char Control;
    unsigned char Length[3];

    } SHOW, *PSHOW;


    Thanks.
    the_init, Mar 22, 2007
    #1
    1. Advertising

  2. the_init wrote:

    > OS: Netware
    > Compiler: Watcom 11.0
    >
    > I am using athe following structure in my program. But when I compile
    > it is giving
    > Error: E1172 Expected struct or union tag but found 0x08 at line 10.
    > i.e. where I have declared the structure.
    > I also searched in google but didn't find any related answer. Please
    > help me.
    >
    > Line 10: struct _SHOW


    just as an experiment change _SHOW -> Show_tag
    in general don't use leading underscores in an identifier
    (they are reserved). Don't use all uppercase for identifiers
    they are normally used for macros. So _SHOW may be
    an implementation defined macro.


    > {
    > unsigned char OC;
    > unsigned char Reserved : 5;
    > unsigned char DeviceNumber : 3;
    > unsigned char Control;
    > unsigned char Length[3];
    >
    > } SHOW, *PSHOW;



    --
    Nick Keighley
    Nick Keighley, Mar 22, 2007
    #2
    1. Advertising

  3. the_init

    Richard Bos Guest

    "the_init" <> wrote:

    > Error: E1172 Expected struct or union tag but found 0x08 at line 10.
    > i.e. where I have declared the structure.


    > Line 10: struct _SHOW


    Either you have a weird non-printable character in your code here, which
    doesn't copy to Usenet (so try deleting the entire line and re-typing it
    afresh), or your compiler is complaining, in a weird way, about you
    using an identifier which starts with an underscore followed by a
    capital letter.
    Identifiers starting with _ and capital, and in many circumstances ones
    staring with _ and anything else as well, are reserved for it (i.e., the
    implementation) to use, and should not be declared by you; it is
    possible that one system header has #defined _SHOW to be 0x08. Since
    such identifiers are reserved for it, it is allowed to do so, and that
    should not break any of your code, because you're _not_ supposed to use
    them.
    If it's the latter problem, a simple solution would be to replace _SHOW
    with something else that does not start with _, for example with SHOW_.
    An even simpler solution would be to realise that struct tags are in a
    namespace of their own, so you can call it struct SHOW and this will not
    conflict with your later typedef SHOW. The very simplest of solutions is
    to realise that you're not referring to this struct as struct _SHOW
    anywhere, so you don't need the tag at all; leaving it out would be
    perfectly OK. You would then need to refer to it as SHOW, not as struct
    SHOW, later on, but you're probably doing that already.

    If it's not either of those problems, there may be something confusing
    the compiler just before this struct declaration; but we can obviously
    not tell what unless you post it.

    > {
    > unsigned char OC;
    > unsigned char Reserved : 5;
    > unsigned char DeviceNumber : 3;
    > unsigned char Control;
    > unsigned char Length[3];
    >
    > } SHOW, *PSHOW;


    BTW, hiding struct SHOW behind a typedef SHOW is all right if it's done
    for the sake of creating an abstract data type; but typedefing a pointer
    to it as well is just needless obfuscation. There's nothing wrong with
    using SHOW * later on, just as there's nothing wrong with using int *
    without a typedef.

    Richard
    Richard Bos, Mar 22, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Garman
    Replies:
    1
    Views:
    649
    Matt Garman
    Apr 25, 2004
  2. Jeff Massung

    Setting union member in structure

    Jeff Massung, Dec 22, 2003, in forum: C++
    Replies:
    2
    Views:
    464
    Jeff Massung
    Dec 22, 2003
  3. Peter Dunker

    union in struct without union name

    Peter Dunker, Apr 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    852
    Chris Torek
    Apr 26, 2004
  4. Maxwell Hammer
    Replies:
    7
    Views:
    629
    Peter Hansen
    Jun 18, 2005
  5. csudha

    Difference between Structure & Union

    csudha, Sep 10, 2004, in forum: C Programming
    Replies:
    4
    Views:
    1,755
Loading...

Share This Page