Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

struct with const string

0 views
Skip to first unread message

David

unread,
Jul 6, 2008, 12:14:34 AM7/6/08
to
Hello,


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!!

Ian Collins

unread,
Jul 6, 2008, 12:16:53 AM7/6/08
to
David wrote:
> Hello,
>
>
> Looking for a solution to take something like:
>
> const TCHAR StrArrayZ[]=_T("Item1\0Item2\0Item3\0");
>
What does that line do? Neither TCHAR or _T are standard C.

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

Ron Ford

unread,
Jul 6, 2008, 12:35:02 AM7/6/08
to
On Sat, 5 Jul 2008 21:14:34 -0700, David posted:

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

rahul

unread,
Jul 7, 2008, 6:57:05 AM7/7/08
to

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.

Nick Keighley

unread,
Jul 8, 2008, 5:49:20 AM7/8/08
to
On 6 Jul, 05:14, "David" <no...@nowhere.com> wrote:

> 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

0 new messages