How about just including this somewhere:
#define myStruct.Var1 myStruct.Var[1]
To be honest, not sure if the above works, and it is a purely syntactical
solution, and may not address the reasons WHY you want this capability.
[==Peter==]
> Hi all,
>
[quoted text clipped - 7 lines]
>
> TIA - Bob
Bob Altman - 19 Sep 2007 20:44 GMT
Well, that's certainly thinking outside of the box. But I'd be surprised if
it compiles.
As for why I want this: I have a structure that is used to pass data into
my public API:
struct MyStates {
BOOL X_Axis_Enabled;
BOOL Y_Axis_Enabled;
BOOL Z_Axis_Enabled;
}
Now, I've decided that it would be very convenient for me to be able to
access the members of this structure as though they were members of an
array, like this:
struct MyStates {
BOOL Enabled[3];
}
But I can't change the structure in a way that will break existing code that
accesses the individual member variables.
- Bob
> How about just including this somewhere:
>
[quoted text clipped - 4 lines]
>
> [==Peter==]
David Wilkinson - 20 Sep 2007 04:29 GMT
> Well, that's certainly thinking outside of the box. But I'd be surprised if
> it compiles.
[quoted text clipped - 18 lines]
> But I can't change the structure in a way that will break existing code that
> accesses the individual member variables.
Bob:
How about
struct MyStates
{
BOOL X_Axis_Enabled;
BOOL Y_Axis_Enabled;
BOOL Z_Axis_Enabled;
BOOL& operator[](int i)
{
BOOL* enabled[3];
enabled[0] = &X_Axis_Enabled;
enabled[1] = &Y_Axis_Enabled;
enabled[2] = &Z_Axis_Enabled;
return *(enabled[i]);
}
};
int main()
{
MyStates myStates;
myStates[0] = TRUE;
myStates[1] = FALSE;
myStates[2] = TRUE;
return 0;
}

Signature
David Wilkinson
Visual C++ MVP
Doug Harrison [MVP] - 19 Sep 2007 20:46 GMT
>How about just including this somewhere:
>
>#define myStruct.Var1 myStruct.Var[1]
>
>To be honest, not sure if the above works
It does not. You can't define a macro name that contains a dot.

Signature
Doug Harrison
Visual C++ MVP
>Hi all,
>
[quoted text clipped - 5 lines]
> myStruct.Vars[1] = 5;
> myStruct.Var1 = 5;
You could do it with:
union U
{
struct
{
char Var0;
char Var1;
char Var2;
};
char Vars[3];
};
This makes use of an anonymous struct, which is a VC extension, so it's not
going to be portable.

Signature
Doug Harrison
Visual C++ MVP
Bob Altman - 19 Sep 2007 21:30 GMT
Thanks Doug, that's just what I was looking for.
- Bob
>>Hi all,
>>
[quoted text clipped - 22 lines]
> not
> going to be portable.