Quote
If the statement
int a[];
isn't a pointer to an array, what is it ?
int *xyz;
'xyz' is the name of a pointer to an integer. Arrays are commonly handled
with a pointer to the first element so it could be a pointer to an array.
int abc[];
'abc' is not a pointer. It is the name of an array. The declaration is
incomplete because the number of elements is not given.
The following is not completely specified becaus of the missing array
dimension.
-----------
enum TYPE {INT, STRING, COLOR};
struct Command
{
char * m_name;
TYPE m_params[];
int m_paramsCount;
};
-----------
The following has 4 'TYPE' items IN the structure. If the dimension of
m_params is changed, the size of the structure will change.
-----------
enum TYPE {INT, STRING, COLOR};
struct Command
{
char * m_name;
TYPE m_params[4];
int m_paramsCount;
};
-----------
The following has NO 'TYPE' items in the structure. What it contains is a
pointer to 'TYPE'. Changing the size of an array whose address 'm_params'
contains does not alter the size of the structure.
-----------
enum TYPE {INT, STRING, COLOR};
struct Command
{
char * m_name;
TYPE *m_params;
int m_paramsCount;
};
-----------
Quote
...For me, an array of ints is just like a array of chars (= string)...
Yes, except for the type of the elements in the array, both work essentially
the same. The issue relates not to an array but to the fact that an array
and a pointer to an element are very different things.
struct X
{
char char_array[6];
};
struct Y
{
char *char_pointer;
};
X xx[] = { { "x1234"; } }
Y yy[] = { { "y1234"; } }
Ignoring any alignment packing issues
sizeof(xx) is 6
sizeof(yy) is 4
X contains the array. Y contains the address of an array. A pointer is not
an array.
Quote
Please, I'd like to understand something. What is the
fundamental difference between :
struct Command { char * m_string; };
Command commands[] = { {"Flicker"} };
The struct is a declaration of a structure type whose structre contains one
element, a 'char*' or pointer to char.
The array declaration attempts to allocate an array of one structure and
initialize the 'char*' variable to the address of the first character of an
anonymous 'const char*' 0-terminated array of characters.
Quote
...But I don't see what would be different from a 16-bit
program for DOS concerning the question I have asked...
There are memory size limitations on DOS programs related to the size of the
array. Depending upon the compiler version the available option settings
related to enums are more limited.
. Ed
Quote
Mark Morrisson wrote in message
news:44c4c8ab$ XXXX@XXXXX.COM ...
The debugguer just catches a memory fault exception.
If the statement
int a[];
isn't a pointer to an array, what is it ?
Please, I'd like to understand something. What is the fundamental
difference
between :
struct Command { char * m_string; };
Command commands[] = { {"Flicker"} };
and
struct Command { int m_array[]; };
Command commands[] = { { {5, 6} } };
?
For me, an array of ints is just like a array of chars (= string),
I don't understand why the compiler should behave differently.
What's wrong in the 2nd form ? It's precisely what I'd like to
understand.
My program is just in Win32 console mode for 32-bit memory
model. Well, it's a classic program. But I don't see what would
be different from a 16-bit program for DOS concerning the
question I have asked.