R
Richard Edwards
If I have the following declaration:
static char *list[1] = {0};
and I execute this code:
list[0] = malloc(10);
am I asking for problems?
Here's what I'm wondering. "list" is a 1 element array of char
pointers. The address that is stored in the 0th element of "list" is a
hard-coded 0. Now, I know that when a pointer is initialized to a
constant value (in practice, this is usually a string), the value that
the pointer points to should not be changed. In this instance, the
array pointer is pointing to 0. The malloc will change the value that
the array pointer points to to the allocated address. If the array
pointer was pointing to a _constant_ 0 that should not be changed, I
could see how this could cause problems.
In reality, does it?
Thanks,
Richard
static char *list[1] = {0};
and I execute this code:
list[0] = malloc(10);
am I asking for problems?
Here's what I'm wondering. "list" is a 1 element array of char
pointers. The address that is stored in the 0th element of "list" is a
hard-coded 0. Now, I know that when a pointer is initialized to a
constant value (in practice, this is usually a string), the value that
the pointer points to should not be changed. In this instance, the
array pointer is pointing to 0. The malloc will change the value that
the array pointer points to to the allocated address. If the array
pointer was pointing to a _constant_ 0 that should not be changed, I
could see how this could cause problems.
In reality, does it?
Thanks,
Richard