cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Calling convention

From: Brian Dessent <brian_at_dessent.net>
Date: Fri, 02 Nov 2007 09:49:54 -0700

Gisle Vanem wrote:

> I know. What I meant to say was that gcc doesn't AFAIK have an option to
> globally use e.g. 'stdcall' for every function (like cl /Gz does). One have to
> specify "int __stdcall foo()" for every declaration.

It does have that: -mrtd. But it's better to pretend that this option
does not exist because using it is usually a very bad idea, since it
means that even just linking to standard libraries (libc
(cygwin/MSVCRT), libgcc, libstdc++, libgfortran, ...) will fail due to
the difference.

> My experience is that when the calling convention is specified, bugs originating
> from wrong calling convention in e.g. function pointers are easier to detect.
> If an application (linking to libcurl) is using "cl /Gr" (fastcall) globally and
> is trying to set a libcurl callback which requires 'cdecl' convention (since libcurl
> was built without "/Gr"), then the compiler would flag it as an *error* when trying
> to convert from 'fastcall' to 'cdecl'. Defining the calling convention in <curl/curl.h>
> avoids rebuilding everything (the application and libcurl) to use the same convention.
> It set the ABI in stone, so to say.

Is this motivated out of the desire to actually fix an existing real
world use case, or just a theoretical? Because it just seems like
stirring a hornet's nest for the heck of it. If a user deliberately
uses a flag that changes default compiler ABI they deserve to have
everything broken unless they recompile all libraries. It just seems
like if this was truly necessary we would have needed to do it years
ago.

Brian
Received on 2007-11-02