473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

Jul 6 '08 #1
4 2022
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.
Jul 6 '08 #2
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
Jul 6 '08 #3
On Jul 6, 9:14*am, "David" <no...@nowhere.comwrote:
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.
Jul 7 '08 #4
On 6 Jul, 05:14, "David" <no...@nowhere.comwrote:
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
Jul 8 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
11
by: Robert Sturzenegger | last post by:
We had a strange problem in a large project with the use of a string class in a static instance of a struct. I managed to reproduce the exactly same problem in a very short program (see below)....
4
by: Angus Comber | last post by:
Hello I have received a lot of help on my little project here. Many thanks. I have a struct with a string and a long member. I have worked out how to qsort the struct on both members. I can...
7
by: tehn.yit.chin | last post by:
I am trying to experiment <algorithm>'s find to search for an item in a vector of struct. My bit of test code is shown below. #include <iostream> #include <vector> #include <algorithm>...
5
by: Bill Pursell | last post by:
Suppose I have a structure with many members, and I pass a pointer to that structure to a function. I'd like the prototype of the function to specify that it will only be changing certain members...
5
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. ...
1
by: swhite | last post by:
Hi, Sorry, not very clear from the title but wasn't sure what to call it. I was experimenting with the following in GCC 4.0.1 and didn't achieve what I expected. I was trying to keep the...
5
by: Alexander Adam | last post by:
Hi! I've got this issue: I have a struct like this: struct node { unsigned int m_code; ?? m_data; unsigned int m_data_size; };
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
1
by: eastlands | last post by:
I need to use an unmanaged c++ dll which uses structs that contain callbacks and also functions. I have included the appropriate c++ definitials and my c# translations below. I first defined the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.