Front Page All Articles Recent Changes Random Article

Contents

Concatenative language

  • ACL
  • Ait
  • Aocla
  • Breeze
  • Cat
  • Cognate
  • colorForth
  • CoSy
  • Deque
  • Elymas
  • Enchilada
  • ETAC
  • F
  • Factor
  • Forth
  • Freelang
  • Gershwin
  • Joy
  • Kitten
  • lang5
  • Lviv
  • min
  • mjoy
  • Mlatu
  • Ode
  • Om
  • Onyx
  • Plorth
  • Popr
  • Porth
  • PostScript
  • Quackery
  • r3
  • Raven
  • Retro
  • Staapl
  • Stabel
  • Trith
  • Worst
  • xs
  • XY
  • 5th
  • 8th

Other languages

  • APL
  • C++
  • Erlang
  • FP trivia
  • Haskell
  • Io
  • Java
  • JavaScript
  • Lisp
  • ML
  • Oberon
  • RPL
  • Self
  • Slate
  • Smalltalk

Computer Science

  • Type systems
  • Language paradigms
  • Compilers
  • Interpreters
  • Garbage collection

Meta

  • Search
  • Farkup wiki format
  • People
  • Etiquette
  • Sandbox

FFI/StructReturns

Returning structs by value on different platforms.

x86-32

On x86-32, we distinguish between "small structs" and "large structs".

On Linux, NetBSD and Solaris, all structs are large structs. On Mac OS X, Windows, FreeBSD and OpenBSD, all structs are small structs except those that satisfy one of the following:

  • The struct is 1, 2, 4 or 8 bytes in size
  • The struct is a C99 complex float value

Small structs

Small structs are returned in EAX:EDX, with the first 4 bytes in EAX and the second 4 bytes in EDX. If the

struct is smaller than 4 bytes in size, EDX is undefined.

Large structs

Large structs are handled as follows. The struct-returning function actually has a hidden first parameter which must be a pointer to a memory area large enough to store the returned struct. This memory area must be supplied by the caller. The EAX and EDX registers are unused in this case.

If the struct-returning function uses the stdcall calling convention (Windows only), then it behaves exactly like a void-returning function with an extra first parameter. However, on non-Windows platforms where the C calling convention is used, the struct-returning function returns with the stack pointer incremented by 4 bytes. So after calling such a function, if you care about the value of ESP, you must decrement ESP by 4 bytes, by pushing a dummy value, for instance.

x86-64

PowerPC

This revision created on Tue, 21 Jul 2009 00:29:08 by slava

Latest Revisions Edit

All content is © 2008-2023 by its respective authors. By adding content to this wiki, you agree to release it under the BSD license.