www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Versioning the linkage attribute

reply David Tiktin <dtiktin nospam.totally-bogus.com> writes:
I'm writing an D interface to a cross-platform C library.  I have the 
Win32 version working using "prototypes" of the form:

export extern (Windows) int dosomething(int);
export extern (Windows) int doanother(char *);

Of course on non-Win32 platforms (Linux and eventually Solaris), (C) 
should replace (Windows) since there API is cdecl :-).  (Or will the 
linux and Solaris compilers be smart enough to know this and "do the 
right thing"?)

I could do:

version (Windows)
{
    	export extern (Windows) int dosomething(int);
    	export extern (Windows) int doanother(char *);
}
else
{
    	export extern (C) int dosomething(int);
    	export extern (C) int doanother(char *);
}

But I'd like to avoid the repetition.  Here's where the C 
preprocessor comes in handy (as a few macros do the trick in the 
library's C code).  Is there a way to do something like this?

version (Windows)
{
    	linkage = Windows;
}
else
{
    	linkage = C;
}

export extern (linkage) int dosomething(int);
export extern (linkage) int doanother(char *);

Or even

export extern
version (Windows){ (Windows) } else { (C) }
{
    	int dosomething(int);
    	int doanother(char *);
}

Neither will compile. ;-(  What's the D Way(tm) to do this?

BTW, why not resolve the "'linux' vs. 'Linux'" issue by having the 
compiler define both?

Dave

-- 
D.a.v.i.d  T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
Jul 08 2004
parent reply "Walter" <newshound digitalmars.com> writes:
Check the thread earlier in this newsgroup entitled:

"version not working with extern(Windows) on linux"

"David Tiktin" dtiktin nospam.totally-bogus.com> wrote in message
 BTW, why not resolve the "'linux' vs. 'Linux'" issue by having the
 compiler define both?
Because then it would cost time to document this, implement it, test it, support it forever, and the fact that there will be two equivalent names will be fodder for never-ending questions about which one they should use. <g> If there are going to be two ways to do something in a language, they should be orthogonal, not almost completely identical.
Jul 08 2004
next sibling parent David Tiktin <dtiktin nospam.totally-bogus.com> writes:
On 08 Jul 2004, "Walter" <newshound digitalmars.com> wrote:

 Check the thread earlier in this newsgroup entitled:
 
 "version not working with extern(Windows) on linux"
Thanks, I hadn't seen that thread.
 "David Tiktin" dtiktin nospam.totally-bogus.com> wrote in message
 BTW, why not resolve the "'linux' vs. 'Linux'" issue by having
 the compiler define both?
Because then it would cost time to document this, implement it, test it, support it forever, and the fact that there will be two equivalent names will be fodder for never-ending questions about which one they should use. <g>
I guess those of us who want to can just do version (linux) { version = Linux; } anyway :-) Dave -- D.a.v.i.d T.i.k.t.i.n t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m
Jul 08 2004
prev sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <cckdp3$2tpo$1 digitaldaemon.com>, Walter says...
Check the thread earlier in this newsgroup entitled:

"version not working with extern(Windows) on linux"

"David Tiktin" dtiktin nospam.totally-bogus.com> wrote in message
 BTW, why not resolve the "'linux' vs. 'Linux'" issue by having the
 compiler define both?
Because then it would cost time to document this, implement it, test it, support it forever, and the fact that there will be two equivalent names will be fodder for never-ending questions about which one they should use. <g> If there are going to be two ways to do something in a language, they should be orthogonal, not almost completely identical.
I suggested once before the possibility of simply making the version specifiers case-insensitive for everything. Linux wouldn't be an exception then, it would be the same as everything else. Maintaining it forever would be a piece of cake - just casefold everything internally. Questions about which one should you use? If it's case-insensitive, there ARE no such questions. Just thinking aloud, Jill
Jul 08 2004
parent "Walter" <newshound digitalmars.com> writes:
"Arcane Jill" <Arcane_member pathlink.com> wrote in message
news:ccles0$1brj$1 digitaldaemon.com...
 I suggested once before the possibility of simply making the version
specifiers
 case-insensitive for everything. Linux wouldn't be an exception then, it
would
 be the same as everything else. Maintaining it forever would be a piece of
cake
 - just casefold everything internally. Questions about which one should
you use?
 If it's case-insensitive, there ARE no such questions.
But then there's the question of why that is case insensitive and everything else in D is case sensitive.
Jul 09 2004