Looking for a solution to take something like:
const TCHAR StrArrayZ[]=_T("Item1\0Item2\0Item3\0");
and convert it to something like:
#include <align1.h>
struct {
union {
const TCHAR StrArrayZ[1];
struct {
const TCHAR I1[]=_T("Item1");
const TCHAR I2[]=_T("Item2");
const TCHAR I3[]=_T("Item3");
const TCHAR Z[]=_T("");
}s;
} u;
} StringOfItems;
#include <alignend.h>
So I could replace the original StrArrayZ with StrOfItems.u.StrArrayZ, but
could also deference each item directly via StrOfItems.u.s.I1, etc..
Is it possible to use the compiler to do it similar to above???
TIA!!
> and convert it to something like:
>
> #include <align1.h>
>
> struct {
> union {
> const TCHAR StrArrayZ[1];
> struct {
> const TCHAR I1[]=_T("Item1");
> const TCHAR I2[]=_T("Item2");
> const TCHAR I3[]=_T("Item3");
> const TCHAR Z[]=_T("");
> }s;
> } u;
> } StringOfItems;
>
> #include <alignend.h>
>
> So I could replace the original StrArrayZ with StrOfItems.u.StrArrayZ, but
> could also deference each item directly via StrOfItems.u.s.I1, etc..
>
> Is it possible to use the compiler to do it similar to above???
>
You'd have to write your own code generator.
--
Ian Collins.
Yikes. align1.h? struct union const TCHAR? This is C salad.
--
I go on working for the same reason that a hen goes on laying eggs.
H. L. Mencken
Looks like you are using some proprietary macros and data types(looks
like Microsoft Visual C++ to me). Your chances of getting help
increase if you just strip down non-standard extensions and post it
again.
> Looking for a solution to take something like:
>
> const TCHAR StrArrayZ[]=_T("Item1\0Item2\0Item3\0");
>
> and convert it to something like:
>
> #include <align1.h>
>
> struct {
> union {
> const TCHAR StrArrayZ[1];
an array with only one entry?
> struct {
> const TCHAR I1[]=_T("Item1");
> const TCHAR I2[]=_T("Item2");
> const TCHAR I3[]=_T("Item3");
> const TCHAR Z[]=_T("");
> }s;
> } u;
>
> } StringOfItems;
>
> #include <alignend.h>
>
> So I could replace the original StrArrayZ with StrOfItems.u.StrArrayZ, but
> could also deference each item directly via StrOfItems.u.s.I1, etc..
>
> Is it possible to use the compiler to do it similar to above???
probably not. I think you want to write some sort of code generator.
Something like
char name_array[MAX_NAMES];
split_input_str (name_array, &name_count, input);
printf ("struct{\n\tunion {\n\tconst TCHAR StrArrayZ[1];\nstruct
{\n");
for (i = 0; i < name_count; i++)
printf ("const TCHAR I1[]=_T(\"name_array[i]\"\n");
this is all untested.
--
Nick Keighley