gcc 4.4.4 c89
I will be adding to this list. So I am looking to NULL terminate it. However, I am getting a warning: "Initialization makes integer from pointer without a cast"
Why does the it mention integer when I haven’t used in that structure?
I was thinking in this case arrays and pointers where the same?
struct company_prof
{
char name[32];
size_t age;
char position[32];
} employee[] = {
{ "Job Bloggs", 23, "software engineer" },
{ "Lisa Low" , 34, "Telecomms Technician" },
{ "simon smith", 38, "personal assistist" },
{ NULL , -1, NULL }
};
Many thanks for any suggestions,
You are attempting to initialize a character array with
NULL. This does not make any sense. For example, you will get the same warning fromand it makes no sense in exactly the same way.
The “integer” that is mentioned in the diagnostic message is the first element of the character array.
charis an integer type in C and when you writeit is an attempt to initialize 0-th element of the array
awithNULL. On your platform,NULLis declared as something with pointer type, which is why the diagnostic message is saying that you are attempting to make an integer (a[0]) from a pointer (NULL) without a cast.An even simpler example might look as follows
and it will earn you the same diagnostic message for the very same reasons.
May I ask why you are attempting to initialize a
charwithNULL? What was your intent?If you don’t intend to write into the
nameandpositionarrays after initialization, maybe you should use pointers instead of arrays as inFormally, in this case
NULLmakes perfect sense. But not in case of array.But less formally the purpose of that
{ NULL, -1, NULL }record at the end of the array is not clear to me though. Is is a terminating element of some kind? Why don’t you just use the exact size of the array instead of creating a terminating element?