Incompatible pointer type warning issued for pointers to structures with compatible first element
Ryan Hajdaj
rhajdaj@yahoo.com
Wed Aug 31 09:54:00 GMT 2005
I was wondering if it were possible to pass a flag to
gcc so that incompatible pointer type warnings were
issued in all cases except cases where a structure's
first element is compatible (although a pointer to the
structure itself may not be).
For example, consider the first argument to the call
to strcpy in the following code:
struct myStruct
{
char string[5];
int i;
}
void func(struct myStruct *pStruct)
{
strcpy (pStruct, "Hello");
return;
}
It would be really nice if the compiler were smart
enough to realize that although a (struct myStruct *)
is not a (char *) (which is what strcpy wants as its
first argument), the first element of a struct
myStruct is of the correct type (char *). ANSI
demands that the address of the first element of a
structure be the same as the address of the structure
itself, so can we tell gcc that pStruct really has two
types (whichever we wish):
1. (struct myStruct *) (address of structure itself)
or
2. (char *) (address of first element)
?
Thanks,
- Hajdaj
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Gcc-help
mailing list