www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Request: "noexport" attribute

reply Michael Butscher <mbutscher gmx.de> writes:
Hi,

the problem I want to solve is that some functions should be exported to a DLL 
(or not) based on a version identifier. This probably could be done also by 
editing the .def file but would be rather inconvenient.


Example:

----------

version(DLL_C)   // If we want a DLL interface for C
{
  export:
  extern(C):
}

int forC_aaa()
{...}

int forC_bbb()
{...}

noexport:  // Stop exporting
extern(D):  // Stop C linkage



int helper()  // Never exported
{...}



version(DLL_D)   // If we want a DLL interface for D
{
  export:
}

int aaa()
{...}

int bbb()
{...}

noexport:  // Stop exporting

----------


It would be nice also if it could be written this way:

version(DLL_D) {export} int aaa()

But maybe hard to implement.



Michael
Jun 07 2005
next sibling parent reply "Uwe Salomon" <post uwesalomon.de> writes:
 version(DLL_C)   // If we want a DLL interface for C
 {
   export:
   extern(C):
 }
AFAIK, this will not work as you expect! version() is not the same as #ifdef and friends, where you "include" something. The scope of export: and extern: ends at the closing brace! Anything after version() will have the normal D linkage. Ciao uwe
Jun 07 2005
next sibling parent Vathix <vathix dprogramming.com> writes:
On Tue, 07 Jun 2005 15:30:14 -0400, Uwe Salomon <post uwesalomon.de> wrote:

 version(DLL_C)   // If we want a DLL interface for C
 {
   export:
   extern(C):
 }
AFAIK, this will not work as you expect! version() is not the same as #ifdef and friends, where you "include" something. The scope of export: and extern: ends at the closing brace! Anything after version() will have the normal D linkage. Ciao uwe
Sometimes { } doesn't introduce a new scope, depending on the statement. In this case I don't think it does and so it should work how he is using it.
Jun 07 2005
prev sibling parent Michael Butscher <mbutscher gmx.de> writes:
Uwe Salomon wrote:
 version(DLL_C)   // If we want a DLL interface for C
 {
   export:
   extern(C):
 }
AFAIK, this will not work as you expect! version() is not the same as #ifdef and friends, where you "include" something. The scope of export: and extern: ends at the closing brace! Anything after version() will have the normal D linkage. Ciao uwe
I tried it and it works (tested with DMD 0.124). Michael
Jun 08 2005
prev sibling parent reply Chris Sauls <ibisbasenji gmail.com> writes:
Since 'export' is a protection attribute, you can end any 'export:' 
attribute-statement by introducing a new protection attribute, such as 
'public'.  In other words:
























 It would be nice also if it could be written this way:
 
 version(DLL_D) {export} int aaa()
 
 But maybe hard to implement.
Maybe the 'alias' statement could be given a new case for attribute symbols... so you could do something like: -- Chris Sauls
Jun 07 2005
parent Michael Butscher <mbutscher gmx.de> writes:
Chris Sauls wrote:
 Since 'export' is a protection attribute, you can end any 'export:' 
 attribute-statement by introducing a new protection attribute, such as 
 'public'.  In other words:
 





















Thank you! Michael
Jun 09 2005