我是一名使用GBDK编写Gameboy ROM的开发者。GBDK自带一个不稳定版本的malloc函数,我无法使其正常工作。同时,我也无法在结构体中嵌套另一个结构体。这使我只能尝试返回一个指针,因此我想知道是否有一种方法可以避免在返回结构体指针时使用malloc函数?
基本上,我的目标是要能够像这样编写代码:
这是我使用malloc编写的代码:
基本上,我的目标是要能够像这样编写代码:
create_struct(struct_name, char member_x, char member_y);
这是我使用malloc编写的代码:
struct point {
char member_x;
char member_y;
};
struct point *makepoint(char member_x, char member_y) {
struct point *temp = malloc(sizeof(struct point));
temp->member_x = member_x;
temp->member_y = member_y;
return temp;
};