Re: Returning structs

Discussion in 'C Programming' started by jacob navia, Dec 16, 2008.

  1. jacob navia

    jacob navia Guest

    Jon Harrop wrote:
    > Is it ok to return structs from functions or are there ABI issues?
    >


    Different compilers will solve this with maybe different methods.
    Binaries could not be compatible.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Dec 16, 2008
    #1
    1. Advertising

  2. jacob navia <> writes:
    > Jon Harrop wrote:
    >> Is it ok to return structs from functions or are there ABI issues?

    >
    > Different compilers will solve this with maybe different methods.
    > Binaries could not be compatible.


    To clarify, binaries may or may not be compatible. (Your statement
    that "Binaries could not be compatible" could mean that binaries will
    not ever be compatible.)

    The C language says its perfectly ok to return structs from functions,
    just as its ok to return integers, pointers, floating-point values, or
    whatever. There may or may not be ABI issues; that depends on the
    ABI, not on the C language. If an ABI for a given platform specifies
    how structs are returned from functions, and if all the compilers on
    that platform obey the ABI, then code from different compilers on that
    platform should be compatible. If not, not.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 16, 2008
    #2
    1. Advertising

  3. Jon Harrop <> writes:
    > Keith Thompson wrote:
    >> The C language says its perfectly ok to return structs from functions,
    >> just as its ok to return integers, pointers, floating-point values, or
    >> whatever. There may or may not be ABI issues; that depends on the
    >> ABI, not on the C language. If an ABI for a given platform specifies
    >> how structs are returned from functions, and if all the compilers on
    >> that platform obey the ABI, then code from different compilers on that
    >> platform should be compatible. If not, not.

    >
    > Is there an ABI for Linux that is adhered to by at least GCC that mandates
    > such behaviour consistently?


    I don't know. Try asking in a Linux newsgroup.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 16, 2008
    #3
  4. Keith Thompson <> writes:

    > Jon Harrop <> writes:
    >> Keith Thompson wrote:
    >>> The C language says its perfectly ok to return structs from functions,
    >>> just as its ok to return integers, pointers, floating-point values, or
    >>> whatever. There may or may not be ABI issues; that depends on the
    >>> ABI, not on the C language. If an ABI for a given platform specifies
    >>> how structs are returned from functions, and if all the compilers on
    >>> that platform obey the ABI, then code from different compilers on that
    >>> platform should be compatible. If not, not.

    >>
    >> Is there an ABI for Linux that is adhered to by at least GCC that mandates
    >> such behaviour consistently?

    >
    > I don't know. Try asking in a Linux newsgroup.


    Crosspost and followup-to comp.os.linux.development.system.

    The ABI varies among the different architectures supported by Linux.
    For x86, Linux and gcc generally conform to the System V ABI, which you
    can find online at
    http://www2.calderasystems.com/developers/devspecs/abi386-4.pdf .
    Chapter 3 is the relevant one. It specifically describes how to return
    structs on page 3-14.

    For x86-64 (aka amd64), you can find the ABI at
    http://www.x86-64.org/documentation/abi.pdf .

    I don't know about other systems, but I expect that similar standards
    exist.

    It's sort of a moot point for Linux, because gcc owns so much of the
    market; even if it wasn't compatible with other implementations, it
    probably wouldn't cause much of a problem, because so few people use the
    other ones. But it should be compatible, anyway.
     
    Nate Eldredge, Dec 16, 2008
    #4
  5. jacob navia

    jacob navia Guest

    Jon Harrop wrote:
    > Keith Thompson wrote:
    >> The C language says its perfectly ok to return structs from functions,
    >> just as its ok to return integers, pointers, floating-point values, or
    >> whatever. There may or may not be ABI issues; that depends on the
    >> ABI, not on the C language. If an ABI for a given platform specifies
    >> how structs are returned from functions, and if all the compilers on
    >> that platform obey the ABI, then code from different compilers on that
    >> platform should be compatible. If not, not.

    >
    > Is there an ABI for Linux that is adhered to by at least GCC that mandates
    > such behaviour consistently?
    >


    Yes there is an ABI.

    The specifications are hard to find but it should be what
    gcc generates. Compilers are not forced to comply. lcc-win
    under linux doesn't comply, and I have been criticized because
    of this.

    The specifications are different when you use 32 or 64 bit linux.


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
     
    jacob navia, Dec 16, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patricia  Van Hise

    structs with fields that are structs

    Patricia Van Hise, Apr 5, 2004, in forum: C Programming
    Replies:
    5
    Views:
    662
    Al Bowers
    Apr 5, 2004
  2. Chris Hauxwell

    const structs in other structs

    Chris Hauxwell, Apr 23, 2004, in forum: C Programming
    Replies:
    6
    Views:
    579
    Chris Hauxwell
    Apr 27, 2004
  3. Paminu
    Replies:
    5
    Views:
    655
    Eric Sosman
    Oct 11, 2005
  4. Daniel Rudy
    Replies:
    15
    Views:
    1,442
    Keith Thompson
    Apr 10, 2006
  5. Tuan  Bui
    Replies:
    14
    Views:
    507
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page