Re: Warning with K&R style function definition
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Thu, 14 Jun 2007 07:20:09 +0200
Old Wolf wrote:
On Jun 14, 12:25 pm, Harald van D k <true...@xxxxxxxxx> wrote:
Old Wolf wrote:
I have some code that has in the header file:
void foo( char bar );
and in the source file:
void foo( bar )
char bar;
{ /* etc. */ }
Your declaration says that the caller passes an argument of type char.
Your definition says that the caller passes an argument of type int [*],
which foo() will convert to a char when the function is called. The
compiler is right to complain.
So the compiler will read the arguments as per K&R,
and not as per the visible prototype?
Yes.
NB. The definition can't be changed to ANSI-style because
it's automatically generated by a third party precompiler.
In your header, you can use
void foo( int bar );
and in your source file, you can either use
void foo( bar )
int bar;
{
char baz = bar;
That was my temporary workaround :)
or if your precompiler can handle it, you can change the header as shown
above, but keep the source file as
void foo( bar )
char bar;
{
I'll give that a go and see if it likes it.
How is the conversion from int to char specified
for these K&R style definitions? Does it read an
int and then convert in the same way as an
ordinary implicit conversion from int to char?
Right. The function call operator will have converted foo's argument to int,
and that argument is then converted "as if by assignment" to char on entry
of foo.
.
- References:
- Warning with K&R style function definition
- From: Old Wolf
- Re: Warning with K&R style function definition
- From: Harald van Dijk
- Re: Warning with K&R style function definition
- From: Old Wolf
- Warning with K&R style function definition
- Prev by Date: Re: structures and alignment issues
- Next by Date: Re: structures and alignment issues
- Previous by thread: Re: Warning with K&R style function definition
- Next by thread: Re: Warning with K&R style function definition
- Index(es):
Relevant Pages
|