[cc65] Passing structs Through Functions

Date view Thread view Subject view

From: Greg King (gngking_at_erols.com)
Date: 2002-02-22 08:59:24

-----Original Message-----
From: Ullrich von Bassewitz <uz_at_musoftware.de>
To: cc65_at_musoftware.de <cc65_at_musoftware.de>
Date: Thursday, February 14, 2002 10:39 AM
Subject: Re: [cc65] dummy questions...

>On Thu, Feb 14, 2002 at 04:22:22PM +0100, groepaz wrote:
>> ...
>> - just to make sure I got this right, the compiler DOES support
>> struct-assignment, but passing structs to functions and/or returning
>> them does NOT work -- right?
>Yes. Returning-structs-from-functions and passing-structs-by-value would
>require larger changes to the compiler, and is often not very useful (because
>of the copying overhead). But, adding struct-assignment was rather easy, and is
>more useful than the other struct operations, so it was added.

The compiler could look at the size of the struct; if it is not larger than an
int or a long int, then cc65 could generate code to pass/receive that structure,
as though it were one of those (single) data-types.  That method would allow you
to add the div() function to the library.

Actually, we can trick the current version of cc65 into using that function:

typedef struct {
    int rem, quot;
    } div_t;

extern div_t fastcall div(int numer, int denom);

    int dividend, divisor;
    div_t result;

    (long)result = (long)div(dividend, divisor);

    /* The test (result.quot * divisor + result.rem == dividend) is true. */

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-02-22 08:59:56 CET