EmbeddedRelated.com
Forums
Memfault Beyond the Launch

CodeWarrior bugs

Started by Unknown April 18, 2005
Hi,

I'm having some quite anoying problems with codewarrior bugs,
related to the lack of code checking by the compiler mostly.

First I had a function that was declared in the header with a
missing argument, but implemented and called with the *extra* argument
( implementation and call in different translation units, but both
including the bogus header ). CW compiled fine, and running on the
hardware *sort* of worked, it did the call, but the params was messed
up. Figured out the header and fixed it. No compiler warning to hint
me, no linking errors saying there wasn't a match for the call. Then
again, I have another call that has the right number of params but one
of their values get in wrong... like mycall( 1, 0, 0 ) and it thinks
the first param is 0!

Am I the only one having this sort of problems with CW? I can't
belive that I found such silly bugs in my first week using it *g*.

Thanks,
Thiago A. Corr



Hi Thiago,
There are probably several reasons:
- you switched off warnings (check if you have -W2 in your command line)
- for your case below (declaring numbers of arguments, but using more in the
call),
you will get a compiler error: ERROR C1821: Wrong number of arguments
So it could be that you did not let the compiler see the declaration?
Maybe you
missed to include the header file? So you have an implicit parameter
declaration
(the compiler warns you about this as well)
- for implicit parameter declaration there is an option -Wpd which flags
this as
error: try it if this is your problem.
- your last problem about order of arguments: this may be one of the above
things. Otherwise
you have to know that for open argument lists (...) the order of arguments
is different too for the compiler.
So here again you have to match the declaration with the implementation in
your sources.

All things above are not a compiler bug: it is more one of the traps and
pitfalls of the C language.

Otherwise I would need a better description/example: contact me either
off-list or contact support@supp... and they could help you out.

Thanks,
Erich

> -----Original Message-----
> From: 68HC12@68HC... [mailto:68HC12@68HC...]
> On Behalf Of Thiago A. Corr
> Sent: Montag, 18. April 2005 17:47
> To: 68HC12@68HC...
> Subject: [68HC12] CodeWarrior bugs >
> Hi,
>
> I'm having some quite anoying problems with codewarrior bugs,
> related to the lack of code checking by the compiler mostly.
>
> First I had a function that was declared in the header with a
> missing argument, but implemented and called with the *extra* argument
> ( implementation and call in different translation units, but both
> including the bogus header ). CW compiled fine, and running on the
> hardware *sort* of worked, it did the call, but the params was messed
> up. Figured out the header and fixed it. No compiler warning to hint
> me, no linking errors saying there wasn't a match for the call. Then
> again, I have another call that has the right number of params but one
> of their values get in wrong... like mycall( 1, 0, 0 ) and it thinks
> the first param is 0!
>
> Am I the only one having this sort of problems with CW? I can't
> belive that I found such silly bugs in my first week using it *g*.
>
> Thanks,
> Thiago A. Corr >
> Yahoo! Groups Links




Hi, thanks for the reply. Some observations did help pinpoint the
problem, but still Im not sure if the compiler is doing the right
thing. I dont know ANSI C, but I do like to think that I know ANSI
C++ very well, and in that case it should give by default errors since
it generates wrong code. But then again, this is C code...

No implicit parameters or elipsis calls, simple call with constants in
the call! The thing is that the include where it was foward declared
was missing in the translation unit, after adding it, worked fine.
*sigh*.

Regards,
Thiago A. Corr

On 4/19/05, Erich Styger <erich.styger@eric...> wrote:
> Hi Thiago,
> There are probably several reasons:
> - you switched off warnings (check if you have -W2 in your command line)
> - for your case below (declaring numbers of arguments, but using more in
> the
> call),
> you will get a compiler error: ERROR C1821: Wrong number of arguments
> So it could be that you did not let the compiler see the declaration?
> Maybe you
> missed to include the header file? So you have an implicit parameter
> declaration
> (the compiler warns you about this as well)
> - for implicit parameter declaration there is an option -Wpd which flags
> this as
> error: try it if this is your problem.
> - your last problem about order of arguments: this may be one of the above
> things. Otherwise
> you have to know that for open argument lists (...) the order of
> arguments
> is different too for the compiler.
> So here again you have to match the declaration with the implementation
> in
> your sources.
>
> All things above are not a compiler bug: it is more one of the traps and
> pitfalls of the C language.
>
> Otherwise I would need a better description/example: contact me either
> off-list or contact support@supp... and they could help you out.
>
> Thanks,
> Erich > > -----Original Message-----
> > From: 68HC12@68HC... [mailto:68HC12@68HC...]
> > On Behalf Of Thiago A. Corr
> > Sent: Montag, 18. April 2005 17:47
> > To: 68HC12@68HC...
> > Subject: [68HC12] CodeWarrior bugs
> >
> >
> >
> > Hi,
> >
> > I'm having some quite anoying problems with codewarrior bugs,
> > related to the lack of code checking by the compiler mostly.
> >
> > First I had a function that was declared in the header with a
> > missing argument, but implemented and called with the *extra* argument
> > ( implementation and call in different translation units, but both
> > including the bogus header ). CW compiled fine, and running on the
> > hardware *sort* of worked, it did the call, but the params was messed
> > up. Figured out the header and fixed it. No compiler warning to hint
> > me, no linking errors saying there wasn't a match for the call. Then
> > again, I have another call that has the right number of params but one
> > of their values get in wrong... like mycall( 1, 0, 0 ) and it thinks
> > the first param is 0!
> >
> > Am I the only one having this sort of problems with CW? I can't
> > belive that I found such silly bugs in my first week using it *g*.
> >
> > Thanks,
> > Thiago A. Corr
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> > ________________________________
> Yahoo! Groups Links > To



Thiago A. Corr wrote:

> Hi, thanks for the reply. Some observations did help pinpoint the
> problem, but still Im not sure if the compiler is doing the right
> thing. I dont know ANSI C, but I do like to think that I know ANSI
> C++ very well, and in that case it should give by default errors since
> it generates wrong code. But then again, this is C code...
>
> No implicit parameters or elipsis calls, simple call with constants in
> the call! The thing is that the include where it was foward declared
> was missing in the translation unit, after adding it, worked fine.
> *sigh*.

Unlike C++ the standard C does not require prototypes. If they are missing
then you will have these problems that you are seeing. I believe that
CodeWarrior has an option to require prototypes for C, and I always
recommend it be on, right now I don't have the HC12 tools so I can verify
this option, but I'm hope someone will.

C has roots in K&R which did not use prototypes and that is part of the
problem. Also prior to C99 (probably another option) if an implicit int was
assumed as return value.

Ron
--
Metrowerks Community Forum is a free online resource for developers
to discuss CodeWarrior topics with other users and Metrowerks' staff
-- http://www.metrowerks.com/community --

Ron Liechty - MWRon@MWRo... - http://www.metrowerks.com


Hi Thiago,
Glad that the problem is sorted out.
ANSI-C is really not catching things like the one below (for legacy reason),
that's why most compiler add options like the -Wpd below to catch things
like this.

On the other side: C++ provides a lot of this things in the language itself,
so I see good reasons to compile your normal C code as C++, as the compiler
can flag more problems automatically. Moreover, due the name encoding,
things like this can be catched in the linker too.
Just a thought.

Erich

> -----Original Message-----
> From: 68HC12@68HC... [mailto:68HC12@68HC...]
> On Behalf Of Thiago A. Corr
> Sent: Mittwoch, 20. April 2005 09:52
> To: 68HC12@68HC...
> Subject: Re: [68HC12] CodeWarrior bugs >
> Hi, thanks for the reply. Some observations did help pinpoint the
> problem, but still Im not sure if the compiler is doing the right
> thing. I dont know ANSI C, but I do like to think that I know ANSI
> C++ very well, and in that case it should give by default errors since
> it generates wrong code. But then again, this is C code...
>
> No implicit parameters or elipsis calls, simple call with constants in
> the call! The thing is that the include where it was foward declared
> was missing in the translation unit, after adding it, worked fine.
> *sigh*.
>
> Regards,
> Thiago A. Corr
>
> On 4/19/05, Erich Styger <erich.styger@eric...> wrote:
> > Hi Thiago,
> > There are probably several reasons:
> > - you switched off warnings (check if you have -W2 in your
> command line)
> > - for your case below (declaring numbers of arguments, but
> using more in
> > the
> > call),
> > you will get a compiler error: ERROR C1821: Wrong number
> of arguments
> > So it could be that you did not let the compiler see the
> declaration?
> > Maybe you
> > missed to include the header file? So you have an
> implicit parameter
> > declaration
> > (the compiler warns you about this as well)
> > - for implicit parameter declaration there is an option
> -Wpd which flags
> > this as
> > error: try it if this is your problem.
> > - your last problem about order of arguments: this may be
> one of the above
> > things. Otherwise
> > you have to know that for open argument lists (...) the order of
> > arguments
> > is different too for the compiler.
> > So here again you have to match the declaration with the
> implementation
> > in
> > your sources.
> >
> > All things above are not a compiler bug: it is more one of
> the traps and
> > pitfalls of the C language.
> >
> > Otherwise I would need a better description/example:
> contact me either
> > off-list or contact support@supp... and they could
> help you out.
> >
> > Thanks,
> > Erich
> >
> >
> > > -----Original Message-----
> > > From: 68HC12@68HC... [mailto:68HC12@68HC...]
> > > On Behalf Of Thiago A. Corr
> > > Sent: Montag, 18. April 2005 17:47
> > > To: 68HC12@68HC...
> > > Subject: [68HC12] CodeWarrior bugs
> > >
> > >
> > >
> > > Hi,
> > >
> > > I'm having some quite anoying problems with codewarrior bugs,
> > > related to the lack of code checking by the compiler mostly.
> > >
> > > First I had a function that was declared in the header with a
> > > missing argument, but implemented and called with the
> *extra* argument
> > > ( implementation and call in different translation
> units, but both
> > > including the bogus header ). CW compiled fine, and
> running on the
> > > hardware *sort* of worked, it did the call, but the
> params was messed
> > > up. Figured out the header and fixed it. No compiler
> warning to hint
> > > me, no linking errors saying there wasn't a match for
> the call. Then
> > > again, I have another call that has the right number of
> params but one
> > > of their values get in wrong... like mycall( 1, 0, 0 )
> and it thinks
> > > the first param is 0!
> > >
> > > Am I the only one having this sort of problems with CW? I can't
> > > belive that I found such silly bugs in my first week
> using it *g*.
> > >
> > > Thanks,
> > > Thiago A. Corr
> > >
> > >
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > ________________________________
> > Yahoo! Groups Links
> >
> >
> > To >
> Yahoo! Groups Links




In version CW version 2.1, the message C1801 flags the call to a function
without a prototype. Make sure this message is active in the compiler
settings.

Bill >Thiago A. Corr wrote:
>
> > Hi, thanks for the reply. Some observations did help pinpoint the
> > problem, but still Im not sure if the compiler is doing the right
> > thing. I dont know ANSI C, but I do like to think that I know ANSI
> > C++ very well, and in that case it should give by default errors since
> > it generates wrong code. But then again, this is C code...
> >
> > No implicit parameters or elipsis calls, simple call with constants in
> > the call! The thing is that the include where it was foward declared
> > was missing in the translation unit, after adding it, worked fine.
> > *sigh*.
>
>Unlike C++ the standard C does not require prototypes. If they are missing
>then you will have these problems that you are seeing. I believe that
>CodeWarrior has an option to require prototypes for C, and I always
>recommend it be on, right now I don't have the HC12 tools so I can verify
>this option, but I'm hope someone will.
>
>C has roots in K&R which did not use prototypes and that is part of the
>problem. Also prior to C99 (probably another option) if an implicit int was
>assumed as return value.
>
>Ron




Thiago A. Corr <thiago.correa@thia...> wrote:

> Hi, thanks for the reply. Some observations did help pinpoint the
> problem, but still Im not sure if the compiler is doing the right
> thing. I dont know ANSI C, but I do like to think that I know ANSI
> C++ very well, and in that case it should give by default errors since

if you "know ANSI C++ very well", you also should also know and use
some flavour of Lint (I recommend PC-Lint for embedded stuff).

"Lint early, lint often. Lint is your friend."

At least lint before you wonder why something doesn't work.

Oliver
--
Oliver Betz, Muenchen



Memfault Beyond the Launch