Click here to Skip to main content
15,502,332 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dynamically create memory based on 2 different struture templates Pin
Richard MacCutchan14-Jun-17 5:32
mveRichard MacCutchan14-Jun-17 5:32 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
manoharbalu14-Jun-17 21:27
manoharbalu14-Jun-17 21:27 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
Richard MacCutchan14-Jun-17 23:40
mveRichard MacCutchan14-Jun-17 23:40 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
manoharbalu14-Jun-17 23:44
manoharbalu14-Jun-17 23:44 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
Richard MacCutchan15-Jun-17 0:18
mveRichard MacCutchan15-Jun-17 0:18 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
manoharbalu15-Jun-17 1:34
manoharbalu15-Jun-17 1:34 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
Richard MacCutchan15-Jun-17 2:11
mveRichard MacCutchan15-Jun-17 2:11 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
leon de boer15-Jun-17 9:06
leon de boer15-Jun-17 9:06 
Seriously it's trivial .. 6 lines of code as combined struct under your other 2 definitions
struct combined_test {
   union {
      struct test1 test1;
      struct test2 test2;
   };  /* you can place a name before the ; if you want a named union */
};
Read the link he gave you or look up unionized structures

So that is an anonymous union.. AKA struct test1 and test2 occupy the same space no extra name needed.
So if you create a combined struct
struct combined_test lets_use_it;  /* allocate a combined struct called lets_use_it */
/* to access it as struct1 */
lets_use_it.test1.z[100] = 10;
/* to access it as struct2 */
lets_use_it.test2.z[100] = 10;
lets_use_it.test1.c12[23] = 10; /* valid but if you try test2.c12 wont work, no such field in struct test2 */
Where it fills in will respect the position in memory layout of test1.z[100] vs test2.z[100]

Now for your pointer it behaves like a pointer to both structs .. again it's UNIONIZED
struct combined_test* p = (struct combined_test*) malloc(sizeof(struct combined_test));
p->test2.z[100] = 32;
p->test1.z[100] = 55;
No rocket science to it and make a sample and debug it if you need to check things.
In vino veritas


modified 15-Jun-17 14:23pm.

GeneralRe: Dynamically create memory based on 2 different struture templates Pin
manoharbalu15-Jun-17 20:54
manoharbalu15-Jun-17 20:54 
GeneralRe: Dynamically create memory based on 2 different struture templates Pin
leon de boer16-Jun-17 5:14
leon de boer16-Jun-17 5:14 
QuestionValue for a structure is not showing in watch window in VS2008 Pin
manoharbalu12-Jun-17 2:14
manoharbalu12-Jun-17 2:14 
AnswerRe: Value for a structure is not showing in watch window in VS2008 Pin
Richard MacCutchan12-Jun-17 7:26
mveRichard MacCutchan12-Jun-17 7:26 
GeneralRe: Value for a structure is not showing in watch window in VS2008 Pin
manoharbalu12-Jun-17 20:14
manoharbalu12-Jun-17 20:14 
GeneralRe: Value for a structure is not showing in watch window in VS2008 Pin
leon de boer12-Jun-17 21:57
leon de boer12-Jun-17 21:57 
QuestionHooking file move with shell extension? Pin
TheHeadlessSourceMan10-Jun-17 22:25
TheHeadlessSourceMan10-Jun-17 22:25 
AnswerRe: Hooking file move with shell extension? Pin
Jochen Arndt11-Jun-17 1:34
professionalJochen Arndt11-Jun-17 1:34 
GeneralRe: Hooking file move with shell extension? Pin
Richard MacCutchan11-Jun-17 2:20
mveRichard MacCutchan11-Jun-17 2:20 
QuestionDisable a textbox based on combo box choice Pin
lolici8-Jun-17 0:07
lolici8-Jun-17 0:07 
AnswerRe: Disable a textbox based on combo box choice Pin
Jochen Arndt8-Jun-17 0:37
professionalJochen Arndt8-Jun-17 0:37 
GeneralRe: Disable a textbox based on combo box choice Pin
lolici8-Jun-17 4:44
lolici8-Jun-17 4:44 
GeneralRe: Disable a textbox based on combo box choice Pin
Jochen Arndt8-Jun-17 5:37
professionalJochen Arndt8-Jun-17 5:37 
GeneralRe: Disable a textbox based on combo box choice Pin
lolici8-Jun-17 12:01
lolici8-Jun-17 12:01 
GeneralRe: Disable a textbox based on combo box choice Pin
Jochen Arndt8-Jun-17 22:17
professionalJochen Arndt8-Jun-17 22:17 
QuestionOverload -> operator Pin
_Flaviu7-Jun-17 0:54
_Flaviu7-Jun-17 0:54 
AnswerRe: Overload -> operator Pin
Jochen Arndt7-Jun-17 1:43
professionalJochen Arndt7-Jun-17 1:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.