N
Nephi Immortal
Is there a way how to create ONE four bytes in memory storage and
four variables can access one str directly? I can do that without
static const and C++ Compiler will be able to compile without any
problem, but static is disallowed in union.
I do not want to use pointer variable to str because I prefer “direct
memory” variable instead of “indirect memory” variable.
union
{
static const char str[ 5 ] = “ABCD”;
struct Letter
{
static const char a;
static const char b;
static const char c;
static const char d;
} letter;
};
char A = letter.a; // read A from str and put it in A variable
char B = letter.b; // read A from str and put it in B variable
char C = letter.c; // read A from str and put it in C variable
char D = letter.d; // read A from str and put it in D variable
four variables can access one str directly? I can do that without
static const and C++ Compiler will be able to compile without any
problem, but static is disallowed in union.
I do not want to use pointer variable to str because I prefer “direct
memory” variable instead of “indirect memory” variable.
union
{
static const char str[ 5 ] = “ABCD”;
struct Letter
{
static const char a;
static const char b;
static const char c;
static const char d;
} letter;
};
char A = letter.a; // read A from str and put it in A variable
char B = letter.b; // read A from str and put it in B variable
char C = letter.c; // read A from str and put it in C variable
char D = letter.d; // read A from str and put it in D variable