Re: [cc65] Another bug?

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-12-19 14:24:02


On Wed, Dec 18, 2002 at 10:54:36AM -0800, Shawn Jefferson wrote:
> Compiling the following code with cc65 2.9.0 for the Atari target and
> running it in SpartaDOS 3.3 causes it to never return control to DOS for some
> reason.

If this is true, it's an atari specific problem. If you have a debugger (maybe
there's one built into the emulator), you can set a breakpoint on _exit. This
label is reached in any case if your program exits regularily (does not
crash). You can then single step through the code and see if the program has
problems in the termination code.

> unsigned char main()

Since code like this has been posted here several times, I would like to add
that this statement generates sub optimal code.

The two function declarations

        void f (void)

and

        void f ()

have a different meaning in C. While the former declares a function that does
not take any parameters, the latter declares a function that may take any
number of parameters (including zero). Since in cc65 compiled code, the called
function pops the parameters (this was choosen because the generated code is
smaller), both function declarations are translated differently, and the
latter one generates more code. So, while it works, you're wasting memory and
the generated code is slower.

As a general rule, if a function does not take any parameters, you should use
"void" as a parameter list.

In case of "main" there are a few additional rules imposed by the C standard.
According to the ISO C standard, the only allowed declarations for main are:

        int main (void);
        int main (int argc, char* argv[]);

Of course, your code will work with cc65, and with a lot of other C compilers,
but at least one should realize that any other declarations of main may cause
problems when porting code to other platforms.

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-12-19 14:24:10 CET