Forum: ARM programming with GCC/GNU tools Return struct in registers

von Bartłomiej K. (bartomiej_k)

Rate this post
0 useful
not useful

I have a problem with return some smalll struct in registers, instead of 
I added -freg-struct-return option to C flags, but compiler omitted it. 
My sample code looks like:
typedef struct
  unsigned int a;
  unsigned int b;
} my_struct;

my_struct my_func ( unsigned int a, unsigned int b )
  my_struct s;

  s.a = a;
  s.b = b;

  return s;
compiled with specified flags
CFLAGS  = -c -Os -freg-struct-return -mthumb -mbig-endian -save-temps

as a result I got
str  r1, [r0, #4]
str  r2, [r0]
bx  lr

but I expected something like
mov  r2, r0
mov  r0, r1
mov  r1, r2
bx  lr

I'm using latest yagarto build but I noticed that problem on other 
toolchain too. Thanks for any hints.

best regards,
Bartłomiej Kubica


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.