Do all C compilers allow functions to return structures?

Posted by Jordan S on Stack Overflow See other posts from Stack Overflow or by Jordan S
Published on 2010-03-10T19:10:55Z Indexed on 2010/03/12 21:17 UTC
Read the original article Hit count: 256

Filed under:
|
|
|

I am working on a program in C and using the SDCC compiler for a 8051 architecture device. I am trying to write a function called GetName that will read 8 characters from Flash Memory and return the character array in some form. I know that it is not possible to return an array in C so I am trying to do it using a struct like this:

//********************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;
}

I don't have any references to this function yet but for some reason, I get a compiler error that says "Function cannot return aggregate." Does this mean that my compiler does not support functions that return structs? Or am I just doing something wrong?

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct