struct with const string

D

David

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

Ian Collins

David said:
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.
 
R

Ron Ford

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

rahul

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

Nick Keighley

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\"\n");


this is all untested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top