我正在使用 C 语言编写程序,并将 SDCC 编译器用于 8051 架构设备。我正在尝试编写一个名为 GetName 的函数,该函数将从闪存中读取 8 个字符并以某种形式返回字符数组。我知道不可能在 C 中返回一个数组,所以我尝试使用这样的结构来完成它:
//********************FLASH.h file*******************************
MyStruct GetName(int i); //Function prototype
#define NAME_SIZE 8
typedef struct
{
char Name[NAME_SIZE];
} MyStruct;
extern MyStruct GetName(int i);
// *****************FLASH.c file***********************************
#include "FLASH.h"
MyStruct GetName( int i)
{
MyStruct newNameStruct;
//...
// Fill the array by reading data from Flash
//...
return newNameStruct;
}
我还没有对这个函数的任何引用,但由于某种原因,我收到一个编译器错误,上面写着“函数无法返回聚合”。这是否意味着我的编译器不支持返回结构的函数?还是我只是做错了什么?