------- Comment #5 from jozef dot behran at krs dot sk  2007-09-26 11:58 -------
Section 5.6.2.1, paragraph 2 says "E1[E2] is equivalent to *((E1)+(E2))". This
means if we have "typedef int THostAddr[8]" then the declaration "THostAddr
*Host" declares Host to be a pointer to 8-item arrays of integers, so the
"const" in "const THostAddr *Host" must be applied to the whole array type
called "THostAddr" and not just the member type of the array type "THostAddr".

Also section 6.7.7, paragraph 3 says "typedef" introduces a synonym to a type
specified by the specifier. Therefore the element type of the "THostAddr[10]"
type is "THostAddr" and not "int" (the element type of "THostAddr"). This
meaning is hidden in the words "a typedef declarator does not introduce a new
type, only a synonym for the type specified" (this implies "a typedef
declarator introduces a synonym for the type specified").

Just to make my point clear: these two array variables don't have the same
element type:

typedef int THostAddr[8];
THostAddr HostList1[10];
int HostList2[80];

The element type of HostList1 is an 8-item array of ints, while the element
type of HostList2 is plain int (so you can write "HostList1[x][y]" but not
"HostList2[x][y]"). If you don't believe me, try this little program:

--- snip ---
#include <stdio.h>

typedef int THostAddr[8];
THostAddr HostList1[10];
int HostList2[80];

int main(void)
{
  printf("%d %d\n",sizeof(HostList1[0]),sizeof(HostList2[0]));
  printf(
    "%d %d\n",
    (int *)(HostList1+1)-(int *)HostList1,
    (int *)(HostList2+1)-(int *)HostList2
  );
  return(0);
}
--- snip ---

It will say "32 4" on my x86 GNU/Linux box (or maybe some other number on
different platforms but the first number will always be 8-times bigger than the
second one). So when the *SIZES* of the element types of the two variables
don't match, they clearly cannot have the same element type.

The conclusion is that you are wrong with the argument in bug 33076. You cannot
say the objects that trigger the spurious warnings have "int" as their element
type, cause they don't have. Their element type is an array of ints. And then
the "const" qualifier must be applied to the whole of this "array of ints" in
these examples according to the standard.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16602

Reply via email to