EmbDev.net

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


von Bartłomiej K. (bartomiej_k)


Rate this post
0 useful
not useful
hi,

I have a problem with return some smalll struct in registers, instead of 
memory.
I added -freg-struct-return option to C flags, but compiler omitted it. 
My sample code looks like:
1
typedef struct
2
{
3
  unsigned int a;
4
  unsigned int b;
5
} my_struct;
6
my_struct my_func ( unsigned int a, unsigned int b )
7
{
8
  my_struct s;
9
10
  s.a = a;
11
  s.b = b;
12
13
  return s;
14
}
compiled with specified flags
1
CFLAGS  = -c -Os -freg-struct-return -mthumb -mbig-endian -save-temps

as a result I got
1
my_func:
2
str  r1, [r0, #4]
3
str  r2, [r0]
4
bx  lr

but I expected something like
1
my_func:
2
mov  r2, r0
3
mov  r0, r1
4
mov  r1, r2
5
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

Reply

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.