Google Groups Home
Help | Sign in
struct with const string
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all
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
David  
View profile
 More options Jul 6, 12:14 am
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!!


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Collins  
View profile
 More options Jul 6, 12:16 am
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.

You'd have to write your own code generator.

--
Ian Collins.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ron Ford  
View profile
 More options Jul 6, 12:35 am
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:

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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
rahul  
View profile
 More options Jul 7, 6:57 am
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:

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.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Keighley  
View profile
 More options Jul 8, 5:49 am
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?

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google