Incompatible pointer type warning issued for pointers to structures with compatible first element

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux