[comp.std.c] Composite type formation question

jsa@edg1.UUCP (J. Stephen Adamczyk) (02/12/91)

Consider this example:

int f(int (*)[]);
int f(a)
int (*a)[3];
{
  return sizeof(*a);
}

I believe the two function types are compatible.  I also believe that a
composite type should be formed.  3.1.2.6 says

"If only one type is a function type with a parameter type list (a function
prototype), the composite type is a function prototype with the parameter
type list."

I believe the second type (in the function definition) does not have
a "parameter type list," so the above seems to suggest that the composite
should just be the type

int f(int (*)[])

taking the parameter type list from the prototyped type.  Is that right?
If that's the case, does that mean that the sizeof is illegal?


Steve Adamczyk (jsa@edg.com or uunet!edg1!jsa; 201-744-2620)

rfg@NCD.COM (Ron Guilmette) (02/17/91)

In article <948@edg1.UUCP> jsa@edg1.UUCP (J. Stephen Adamczyk) writes:
+Consider this example:
+
+int f(int (*)[]);
+int f(a)
+int (*a)[3];
+{
+  return sizeof(*a);
+}
+
+I believe the two function types are compatible.  I also believe that a
+composite type should be formed.  3.1.2.6 says
+
+"If only one type is a function type with a parameter type list (a function
+prototype), the composite type is a function prototype with the parameter
+type list."
+
+I believe the second type (in the function definition) does not have
+a "parameter type list," so the above seems to suggest that the composite
+should just be the type
+
+int f(int (*)[])
+
+taking the parameter type list from the prototyped type.  Is that right?

I believe that you are completely correct down to this point.

+If that's the case, does that mean that the sizeof is illegal?

I'm not sure.  While it would seem that the function itself gets a
"composite" type, I think that it is entirely less than clear that
this influences the type of the formal parameter variable `a'.

Either way, this would make an excelent test case for a compiler test
suite!  I feel pretty sure that there is only one "right" answer (even
if I'm not sure what it is).

-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.