On 2011-10-17 13:41:14 +0000, Jacob Carlborg <d...@me.com> said:

On 2011-10-17 14:01, Michel Fortin wrote:
On 2011-10-17 10:21:45 +0000, Sean Kelly <s...@invisibleduck.org> said:

There's also the occasional issue of something that doesn't translate
into D. As one slightly weird example, some of the the Posix routines
in OSX have alternates with odd suffixes like "$2003" that are the
versions which should be called on newer versions of the OS. I'm still
not sure of the best way to handle this, since D doesn't have macros.

I think what D needs to handle that is some pragma to manually specify
the mangled name of a given function. Why would you need macros?

Perhaps the macro is used to determine if "foo" or "foo$2003" is supposed to be called, based on some condition.

Indeed. The condition is which OS release you're targeting. That can be accomplished today through static ifs. Although it'd be a little more verbose since you'd have to repeat the function prototype.

If we had a way to do conditional attributes in D it'd be awesome for this use case. It could work this way for instance:

        static if (MAC_OS_X_VERSION_MIN_REQUIRED == 10.5)
                @deprecated_in_os_x_10_5 = deprecated;
        else
                @deprecated_in_os_x_10_5 = /* nothing */;

        @deprecated_in_os_x_10_5
        void some_function_deprecated_in_os_x_10_5();   
Or this way for the special mangled names:

static if (MAC_OS_X_VERSION_MIN_REQUIRED == 10.5) @darwin_alias(name) = pragma(symbol_name, name ~ "$UNIX2003");
        else
                @darwin_alias(name) = pragma(symbol_name, name);

        @darwin_alias("fwrite")
size_t fwrite(const void * /*__restrict*/, size_t, size_t, FILE * /*__restrict*/);

Internally, when the compiler sees @darwin_alias("fwrite") it just replaces it with the attributes @darwin_alias was supposed to be. Note that I'm *not* proposing a macro system: this would work at the semantic level as a special kind of attribute.

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to