T
Timo
I am trying to get address of myStruct to a string array texts[].
I am using M$ Visual C++ 6.0 (this is not OS specific question, though,
this code should also work on 16 bit embedded compiler
).
This is my code:
typedef struct
{
const unsigned short a;
const unsigned long b;
} testStruct;
const testStruct myStruct[] =
{
0x0001, 0x00000002,
0x0003, 0x00000004
};
#define STR_LEN_MAX 15
const unsigned char texts[][STR_LEN_MAX] =
{
&myStruct[0], "string 1",
"string 2",
"string 3"
};
When I run the code, debugger shows the content of texts[] as:
00 73 74 72 69 6E 67 20 31 00 00 00 00 00 00
73 74 72 69 6E 67 20 32 00 00 00 00 00 00 00
73 74 72 69 6E 67 20 33 00 00 00 00 00 00 00
As you can see, the address of myStruct (0x00422020 in this case), is
not stored. I also tried some other syntaxes with no success:
(testStruct *)&myStruct[0], "string 1",
It seems that compiler is only storing 8 bits of address of myStruct
to texts[] array, which I guess is correct, because texts[] is 2-dimensional
unsigned char array. So, I figured out that I should store each byte
of myStuct address seperately, tried this:
(unsigned char *)(&myStruct[0] & 0xff), "string 1",
Compiler gives error:
error C2296: '&' : illegal, left operand has type 'const struct testStruct *'
Another guess:
(unsigned char *)((&myStruct[0]) & 0xff), "string 1",
-> error C2296: '&' : illegal, left operand has type 'const struct testStruct *'
Is there any way I can do this?
BR,
Timo
I am using M$ Visual C++ 6.0 (this is not OS specific question, though,
this code should also work on 16 bit embedded compiler
This is my code:
typedef struct
{
const unsigned short a;
const unsigned long b;
} testStruct;
const testStruct myStruct[] =
{
0x0001, 0x00000002,
0x0003, 0x00000004
};
#define STR_LEN_MAX 15
const unsigned char texts[][STR_LEN_MAX] =
{
&myStruct[0], "string 1",
"string 2",
"string 3"
};
When I run the code, debugger shows the content of texts[] as:
00 73 74 72 69 6E 67 20 31 00 00 00 00 00 00
73 74 72 69 6E 67 20 32 00 00 00 00 00 00 00
73 74 72 69 6E 67 20 33 00 00 00 00 00 00 00
As you can see, the address of myStruct (0x00422020 in this case), is
not stored. I also tried some other syntaxes with no success:
(testStruct *)&myStruct[0], "string 1",
It seems that compiler is only storing 8 bits of address of myStruct
to texts[] array, which I guess is correct, because texts[] is 2-dimensional
unsigned char array. So, I figured out that I should store each byte
of myStuct address seperately, tried this:
(unsigned char *)(&myStruct[0] & 0xff), "string 1",
Compiler gives error:
error C2296: '&' : illegal, left operand has type 'const struct testStruct *'
Another guess:
(unsigned char *)((&myStruct[0]) & 0xff), "string 1",
-> error C2296: '&' : illegal, left operand has type 'const struct testStruct *'
Is there any way I can do this?
BR,
Timo