I have the following scenario (code that I inherited...):
<header file>
extern short foo( type1, type2 );
<C file>
short foo( const type1 var1, const type2 var2 ) { /*...*/ }
Is it legal to have a function definition contain a type qualifier that
is not specified in the function declaration?
I have looked in the CLC FAQ, K&R2, and the C9X draft (I don't have
ready access to C89), but did not find any info relating to mismatches
in the definition & declaration...
If this is OK (or even if it isn't), could you please point me to the
correct section of the standard, page # in K&R2, etc. that I could refer
to?
(this is probably irrelevant...)
Old versions of the compiler I am using had no problems (no errors, no
warnings) with the above code, but the latest version complains with the
following errors:
Type of the parameter cannot conflict with previous declaration of
function foo.
Previous declaration has type C function returning signed short
integer.
Redeclaration has type C function returning signed short integer.
Thanks,
Curt
void foo(short*);
and a function definition:
void foo(const short* ps)
{}
you will have an error because your first parameter is defined differently.
Daniel
<header file>
extern short foo( type1, type2 );
<C file>
short foo( const type1 var1, const type2 var2 ) { /*...*/ }
Is it legal to have a function definition contain a type qualifier that
is not specified in the function declaration?
No, it's not legal.
I have looked in the CLC FAQ, K&R2, and the C9X draft (I don't have
ready access to C89), but did not find any info relating to mismatches
in the definition & declaration...
If this is OK (or even if it isn't), could you please point me to the
correct section of the standard, page # in K&R2, etc. that I could refer
to?
$ 6.1.2.6: Compatible type and composite type
...
$ All declarations that refer to the same object or function shall have
$ compatible type; otherwise, the behavior is undefined.
$ 6.5.3: Type qualifiers
...
$ For two qualified types to be compatible, both shall have the
$ identically qualified version of a compatible type; ...
--
"I ran it on my DeathStation 9000 and demons flew out of my nose." --Kaz
Please: do not email me copies of your posts to comp.lang.c
do not ask me C questions via email; post them instead
In article <87hfxgc...@pfaffben.user.msu.edu>,
Ben Pfaff <pfaf...@pilot.msu.edu> wrote:
>$ 6.1.2.6: Compatible type and composite type
> ...
>$ All declarations that refer to the same object or function shall have
>$ compatible type; otherwise, the behavior is undefined.
>
>$ 6.5.3: Type qualifiers
> ...
>$ For two qualified types to be compatible, both shall have the
>$ identically qualified version of a compatible type; ...
The clause 6.1.2.6 says that additional compatibility rules are found
in clause 6.5.4 (and any of its subclauses, by implication). So it's
unfortunately not enough to look at 6.5.3.
[...]
Is there something that changes the situation in this particular
subcase? I agree that this is not exhaustive, but I don't see
anything that allows what he wrote.
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)
>k...@cafe.net (Kaz Kylheku) writes:
>
> In article <87hfxgc...@pfaffben.user.msu.edu>,
> Ben Pfaff <pfaf...@pilot.msu.edu> wrote:
> >$ 6.1.2.6: Compatible type and composite type
> > ...
> >$ All declarations that refer to the same object or function shall have
> >$ compatible type; otherwise, the behavior is undefined.
> >
> >$ 6.5.3: Type qualifiers
> > ...
> >$ For two qualified types to be compatible, both shall have the
> >$ identically qualified version of a compatible type; ...
>
> The clause 6.1.2.6 says that additional compatibility rules are found
> in clause 6.5.4 (and any of its subclauses, by implication). So it's
> unfortunately not enough to look at 6.5.3.
>[...]
>
>Is there something that changes the situation in this particular
>subcase? I agree that this is not exhaustive, but I don't see
>anything that allows what he wrote.
It is in Kaz's other article. The bottom of 6.5.4.3 (just before the
examples) says "For each parameter declared with qualified type, its type
for these comparisons is the unqualified version of its declared type."
The original declarations are compatible.
--
-----------------------------------------
Lawrence Kirby | fr...@genesis.demon.co.uk
Wilts, England | 7073...@compuserve.com
-----------------------------------------