[cc65] Problem assigning structs

From: Andreas Koch <email1kochandreas.com>
Date: 2007-11-10 23:18:58
Hi all,

i have a little problem when using structs. The docs state that
functions can't return structs, so i have them fill a global
struct and assign that to the desired target variable. While
this compiles, it seems to lead to memory corruption at runtime.

Using cc65 2.11. Test app:

-----------------------
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <cbm.h>
#include <dbg.h>
#include <stdlib.h>

struct tests {
unsigned char test1[16];
unsigned char test2[8];
unsigned char test3,test4;
unsigned char a,b,c,d,e;
int f,g,h;
};

struct tests str1;
struct tests str2;


void loadstr1()
{
	int x;
	for (x=0;x<16;x++) str1.test1[x]=42;
	for (x=0;x<7;x++) str1.test2[x]=42;
	str1.h=42;
}

int main()
{
   loadstr1();
   printf("str1.test1[0]= %i \n",str1.test1[0]);
   printf("str1.h       = %i \n",str1.h);
   str2=str1;
   printf("str2.test1[0]= %i \n",str2.test1[0]);
   printf("str2.h       = %i \n",str2.h);
}
----------------------------
This returns 42 for the str1 values, and 0 for the str2 values. 
Depending on the other code in the app it can also create random errors 
(got "syntax error in line 638" in one case but can't reproduce that now)

Is this a bug or am i doing something wrong here?

thanks,
   Andreas




----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Nov 10 23:18:16 2007

This archive was generated by hypermail 2.1.8 : 2007-11-10 23:18:20 CET