Re: legality of forward declaration



On Thu, 01 Jun 2006 07:46:36 GMT, "Antoine Trux"
<antoine.trux@xxxxxxxxx> wrote in comp.lang.c:

Absolutely a bug in Code Warrior. In function declarations, "type
name []" is exactly equivalent to "type *name", with the exception of
a special case for compilers conforming to the 1999 or later version
of the C standard, and that special case does not apply here.

Then, how do you interpret the following paragraph from the C99 Standard
(thanks to Harald van Dijk for pointing it out):

------> start of C99 Standard excerpt <------
6.7.5.2 Array declarators
Constraints
1 In addition to optional type qualifiers and the keyword static, the [
and ] may delimit
an expression or *. If they delimit an expression (which specifies the size
of an array), the
expression shall have an integer type. If the expression is a constant
expression, it shall
have a value greater than zero. The element type shall not be an incomplete
or function
type. The optional type qualifiers and the keyword static shall appear only
in a
declaration of a function parameter with an array type, and then only in the
outermost
array type derivation.

------> end of C99 Standard excerpt <------
?

Antoine

The issue is not how I interpret this clause of the C standard, but
rather how I determine that this clause does not apply. In the
parameter section of a function declarator, this is _not_ an array
declarator.

That is made clear by the following:

6.7.5.3 Function declarators (including prototypes)

[snip]

7 A declaration of a parameter as ??array of type?? shall be adjusted
to ??qualified pointer to type??, where the type qualifiers (if any)
are those specified within the [ and ] of the array type derivation.
If the keyword static also appears within the [ and ] of the array
type derivation, then for each call to the function, the value of the
corresponding actual argument shall provide access to the first
element of an array with at least as many elements as specified by the
size expression.

So the standard requires that this:

return_type func_name(type param_name [])

....be adjusted to, and compiled exactly the same as:

return_type func_name(type *param_name)

Of course, "param_name" is optional if the declaration is not the
definition of the function.

So any compiler that complains that "type param_name []" in a function
declaration is violating the constraint against declaring an array of
incomplete type, it is the compiler that is in error. The compiler is
failing to perform the adjustment that 6.7.5.3 p7 requires of it. The
"shall" in this sentence is a requirement on the compiler, not the
programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: Do buffers always start with the lowest memory address being the first element?
    ... > The C standard does not assume a downward-growing stack, ... > an upward-growing stack. ... C allows but does not require that the array produced ... > machine depends on both the C compiler and the machine. ...
    (comp.lang.c)
  • Re: Structure
    ... I am having Linux platform.I am declaring the array of ... Using " extern ",to extern the structure but when i ... Unless you have a C99 compiler, you need a return statement here. ... You could repeat the declaration of the type from main.c here. ...
    (comp.lang.c)
  • Re: SOCKET problem
    ... //I am still trying to create a Socket and use it ... I guess you have something BEFORE the declaration that ... Microsoft's compiler "doesn't use standard C", ...
    (comp.lang.c)
  • Re: Something wrong in my program
    ... foo.c:27: warning: implicit declaration of function `isspace' ... This lets the compiler help you out by ... The array size below is not a constant expression. ... buffer array "static" (often a bad idea in larger programs, ...
    (comp.lang.c)
  • Re: prototypes
    ... Before there was a real standard. ... Your compiler is in a mode such that it accepts ... Implicit int, and implicit function declaration, which is ... Note particularly the phrasing 'correct prototype'. ...
    (comp.lang.c)