Re: [cc65] k&r c

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-06-10 15:25:43


Hi!

Sorry for the late answer, I have been busy and out of town for a few days.

On Fri, Jun 07, 2002 at 03:46:50PM +0200, Christian Groessler wrote:
[return from k&r function]

> I recently tried to compile a k&r c program with cc65 and found some
> inconstistent behaviour.

> Consider the following code
>
> ---------
> bla(s)
>      int s;
> {
>      if (s == 0)
>          return;
> }
> ---------
>
> cc65 refuses to compile it, I get
>
> t.c(7): Error: Function `bla' must return a value
>
> If I replace the "return;" with "return 0;" it gets compiled.
>

> So my question, why is this an error and not a warning only?

Not returning anything from a function that returns something is definitely an
error - at least for new style (ANSI) functions. You are right however, for
K&R functions, this should be relaxed, since there is no "void" type in K&R,
so it is not possible to declare a function that returns nothing.

> And, if it should be an error, why is it no error when I simply drop
> out of the function without a return?

It is still an error (called "undefined behaviour" in the standard), but it is
not flagged by cc65, because the execution flow tracking done by cc65 is not
good enough to get all cases right. cc65 would flag quite some false
positives, so I've removed the error message in this case. Please note that
"undefined behaviour" does not need a diagnostic, so even if the treatment is
quite suboptimal, at least it's standard compliant:-)

Regards


	Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2002-06-10 15:27:12 CEST