Error related to Structure or Union

T

the_init

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.
 
N

Nick Keighley

the_init said:
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;
 
R

Richard Bos

the_init said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top