Re: struct & enum & :: visibility operator by Joe
Joe
Sun Aug 03 22:17:57 CDT 2008
On Jul 19, 3:10=A0am, "robbio" <roberto...@supereva.it> wrote:
> "Joe.M" <choly...@gmail.com> wrote in message
>
> news:ddaab242-9f68-4b47-849e-135c4d538141@c2g2000pra.googlegroups.com...
> On Jul 18, 2:32 am, "robbio" <roberto...@supereva.it> wrote:
>
>
>
> > Hi at all,
>
> > I have a header file like this:
>
> > -------- file.h ------------
> > ...
> > extern "C"
> > {
> > ...
> > typedef struct _S S;
> > ...
>
> > struct _S
> > {
> > ...
> > enum
> > {
> > a,
> > b
> > }myenum;
> > ...
> > };}
>
> > --------- end of file.h -------------
>
> > and a C file like this
>
> > ----------- file.c ----------------
>
> > ....
> > #include "file.h"
>
> > static void myFunc(S* pS)
> > {
> > ....
> > if (... =3D=3D _S::a)
> > ....
> > ....
>
> > }
>
> > -----------end of file.c --------------
>
> > I'm using the Microsoft 2005 environment and so its compiler. The compi=
ler
> > says me that there is an error in myFunc, the error is that _S is an
> > undeclared indentifier. I'm not an expert of C but I don't know where t=
he
> > problem is.
>
> > Can anyone help me, please?
>
> > thanks a lot
> > roberto
>
> I think the :: operator only in C++ not in C, so u should write like
> the following:
> if (a =3D=3D pS->myenum)
> --------------------------------
>
> I know that in C++ it works, because a struct is a particular instance of=
a
> class with all members public by default and the scopre operator :: is
> valid.
> =A0I wanted use _S::a or _S::b into the if stament.
> I think the problem is conceptual, that is: a declaration like that, stru=
ct
> _S {...}; is only a declaration of a type like int or char or similar,so =
you
> cannot use a type in an expression like that in the if stament, so the
> compiler tried to search for a reasonable variable _S to use into the if
> statement and it couldn't find, because struct _S is not a valid expressi=
on
> to put into it, maybe...
>
> thanks a lot anyway
> roberto
Hi,
I know what's u want to do, u are missing my code meaning. So I paste
the demo here:
typedef struct _S S;
struct _S {
enum {
a,
b
} myenum;
};
int _tmain(int argc, _TCHAR* argv[])
{
S s1;
s1.myenum =3D a;
if (s1.myenum =3D=3D a)
_tprintf_s(_T("is ok!\n"));
else
_tprintf_s(_T("is failed!\n"));
return 0;
}
summary:
1. In c, the enum is the global const int.
2. _S is just the type's tag no other meanings.