TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Jonathan de Boyne Pollard
from: Paul Edwards
date: 1996-02-01 22:39:40
subject: callconv.txt

> EMX
 > Uses the C calling convention only

JdBP>   Then how can one call the system API ?

With great difficulty?  Actually, the only problem is system APIs
that return structures.  I don't know of any such APIs offhand.
Presumably you can't use them.

JdBP>   I don't think that you are right.  *ALL* compilers support the SYSTEM
JdBP>   calling convention.

If you can interpret the following quote from EMX 0.9a, you
may have the answer.  BFN.  Paul.


The calling convention used by GCC is almost compatible with the
`system' calling convention of IBM C Set/2.  Structures are returned
differently: IBM C Set/2 uses a hidden parameter which is removed from
the stack by the caller, GCC returns the structure in registers EAX
and EDX if its size is 8 bytes or less (-freg-struct-return is the
default).  GCC uses a hidden parameter if the size of the structure is
more than 8 bytes, but the callee removes the hidden parameter from
the stack.  Currently, the GCC option -fpcc-struct-return doesn't
solve that problem.  Instead, rewrite the function and the function
call as follows:

    /* Original code */
    struct s1 func1 (int a1)
    {
      struct s1 t1;
      ...
      return (t1);
    }
    ...
    
    struct s1 v1;
    v1 = f1 (0);

    /* Modified code */
    
    struct s1 *f1 (struct s1 *ret, int a1)
    {
      struct s1 t1;
      ...
      *ret = t1;
      return (ret);
    }
    
    ...
    
    struct s1 v1;
    f1 (&v1, 0);
@EOT:

---
* Origin: X (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.