Re: legality of forward declaration
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Thu, 01 Jun 2006 23:10:13 -0500
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
.
- Follow-Ups:
- Re: legality of forward declaration
- From: Harald van Dijk
- Re: legality of forward declaration
- References:
- Re: legality of forward declaration
- From: Antoine Trux
- Re: legality of forward declaration
- Prev by Date: Re: how to parse an executable in C and find out if there is any return(RET in assembly) or not
- Next by Date: Re: Question about random generator.
- Previous by thread: Re: legality of forward declaration
- Next by thread: Re: legality of forward declaration
- Index(es):
Relevant Pages
|