THE WAKE UP CHANNEL
Go to bottomPage: 1
TOPIC:
#2177
ZNEO Compiller Question About Dynamic frames call 1 Year, 2 Months ago Karma: 0
I have a routine call that returns a structure. Upon call to "return *val;"
where val is a pointer to structure the return value was wrong. upon examining
the assembly. inside the functions body the R1 register which hold the frame
pointer was modified by the compiler without saving its value so when the
function exit it return a wrong value(maybe its because of the modified R1 value).


//////////////////////////////code///////////////////////////////////////////////////////
#include "string.h"

typedef struct{
int (*setval) (void * _this);
}base_cls__vptr0;

typedef struct base_cls_s{
base_cls__vptr0 * vptr0;
char base_cls__ghost_var ;
}base_cls;
#define THIS_base_cls ((base_cls*)_this)

int base_cls__setval(void * _this);
base_cls base_cls__constructor(void * _this);

typedef struct{
int (*setval) (void * _this);
}mcls__vptr0;
typedef struct mcls_s{
mcls__vptr0 * vptr0;
char base_cls__ghost_var ;
unsigned char mcls___data [4];
}mcls;
#define THIS_mcls ((mcls*)_this)
mcls mcls__constructor(void * _this,int v);



base_cls__vptr0 base_cls__vptr0init={base_cls__setval};
int base_cls__setval(void * _this){
return 1;
}
base_cls base_cls__constructor(void * _this){
THIS_base_cls->vptr0 = &base_cls__vptr0init;
return *THIS_base_cls;
}

mcls__vptr0 mcls__vptr0init={base_cls__setval};

mcls mcls__constructor(void * _this,int v){
THIS_mcls->vptr0 = &mcls__vptr0init;
f_f_memcpy(THIS_mcls->mcls___data,&v,4); // structure value is correct
return *THIS_mcls; // this part is the problem
}





mcls test ;
void class_init(void){
mcls__constructor(&test,0x12345678);
}
void setup(){
class_init();
// put your setup code here, to run once:
}
void main(void){
setup();
while(1){
// put your main code here, to run repeatedly:
}
}
//CObjectEndDeclare
//CPPObjectEndDeclare
rakschiptron (User)
Fresh Boarder
Posts: 7
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 1
The Sample Center is managed separately
from Zilog's Customer Support services,
and therefore requires a separate login.
Acknowledged! Take me to the Sample Center.
Disable this pop-up in the future.