Re: [cc65] c programm

Date view Thread view Subject view

From: Marc 'BlackJack' Rintsch (marc_at_rintsch.de)
Date: 2003-02-05 22:22:19


On Wednesday 05 February 2003 21:26, 3843416 wrote:
> kann sich einer vorstellen, warum folgendes programm nicht funzt ?

He asks why the program doesn't work.

> typedef struct{
>         char color1, color2;
> } ROYWINCOL_T;

This defines a type but doesn't reserve any space for the struct. Add

ROYWINCOL_T a;

to actually have a variable named "a" of that type.

> void  setcharcolors(ROYWINCOL_T colors);

Here you declare a function 'setcharcolors' which takes a ROYWINCOL_T 
struct as argument, but it's implementation isn't defined. What should 
happen if you call this function?

> void main(void){
>         setcharcolors({1,0});
> }

A compiler doesn't know what to do with "{1,0}". You/it can't tell what 
type it is. It compiles with gcc if you cast it to ROYWINCOL_T: 
setcharcolors((ROYWINCOL_T){1,0});

It doesn't work in cc65. Maybe because that's a non standard way of 
using anonymous structs (correct term?) but I remember vaguely that 
cc65 can't pass structs as function parameters. So maybe you want to 
rewrite it this way:

typedef struct{
        char color1, color2;
} ROYWINCOL_T;

ROYWINCOL_T a;

void  setcharcolors(char c1, char c2) {
    a.color1 = c1;
    a.color2 = c2;
}

void main(void){
        setcharcolors(1,0);
} 

Ciao,
	Marc 'BlackJack' Rintsch
-- 
"He who laughs last thinks slowest"

----------------------------------------------------------------------
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 : 2003-02-05 22:31:49 CET