The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.c
From:
"David" <no... @nowhere.com>
Date: Sat, 5 Jul 2008 21:14:34 -0700
Local: Sun, Jul 6 2008 12:14 am
Subject: struct with const string
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!!
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.c
From:
Ian Collins <ian-n... @hotmail.com>
Date: Sun, 06 Jul 2008 16:16:53 +1200
Local: Sun, Jul 6 2008 12:16 am
Subject: Re: struct with const string
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.
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.c
From:
Ron Ford <r... @nowhere.net>
Date: Sat, 5 Jul 2008 22:35:02 -0600
Local: Sun, Jul 6 2008 12:35 am
Subject: Re: struct with const string
On Sat, 5 Jul 2008 21:14:34 -0700, David posted:
> 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!!
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
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.c
From:
rahul <rahulsin... @gmail.com>
Date: Mon, 7 Jul 2008 03:57:05 -0700 (PDT)
Local: Mon, Jul 7 2008 6:57 am
Subject: Re: struct with const string
On Jul 6, 9:14 am, "David" <no... @nowhere.com> wrote:
> 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!!
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.
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.c
From:
Nick Keighley <nick_keighley_nos... @hotmail.com>
Date: Tue, 8 Jul 2008 02:49:20 -0700 (PDT)
Local: Tues, Jul 8 2008 5:49 am
Subject: Re: struct with const string
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
You must
Sign in before you can post messages.
You do not have the permission required to post.