Re: [cc65] returning structs

From: Groepaz <>
Date: 2009-08-10 11:58:19
On Montag 10 August 2009, Groepaz wrote:
> hu? how would calling memcpy destroy the data that was passed to it? if it
> does that its just broken. what you say might be a problem if
> thefuncthatreturnsstruct() actually DOES return a struct by value - i
> wouldnt know since i never use this particular c feature. but even then i
> would expect memcpy not to destroy any data that is beeing passed to it :)

to make it more clear, some pseudocode (i can only guess that you think about 
a different scenario)

"original", passing struct as value

typedef struct
  int bar;
} foo;

foo func(void)
  foo bla;
  return bla;

int main(void)
  foo blub;

"workaround", copying the struct

foo func(void)
  static foo bla;

  ^^^ there is the problem. i see what you mean now too =)

  return &bla;

int main(void)
  foo blub;

so the workaround isnt exactly as problematic as you say, if you can live with 
declaring the struct you want to return static, and "func" no more beeing 
reentrant. as far as typical cc65 apps go.... no problem i think :)


Die Majorität der Dummen ist unüberwindbar und für alle Zeiten gesichert. Der 
Schrecken ihrer Tyrannei ist indessen gemildert durch Mangel an Konsequenz. 
<Albert Einstein>

To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Aug 10 11:57:52 2009

This archive was generated by hypermail 2.1.8 : 2009-08-10 11:57:54 CEST