www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Confusion over version (xxx)

reply Ken Barry <kb9888 gmail.com> writes:
Just learning D, working with GLFW and dmd 1.030 on WinXP. The files glfw.d,
gl.d and glu.d shipped with the GLFW distribution contain the following...

version (Win32) {
    extern (Windows):
}
version (linux) {
    extern (C):
}

...which results in Symbol Undefined errors.
One of the files contains a variation...

version(Win32)
   extern(Windows):
else
   extern(C):

...which results in a syntax error on the 'else'.
I have tried all the variations I can think of, such as

version(Win32)
{
   extern(Windows):
}
else
{
   extern(C):
}

which also results in Symbol Undefined errors.
The only thing that works is...

version(Win32):

...on it's own. So I'm confused and would really appreciate it if anyone can
explain this behaviour.
Aug 15 2008
next sibling parent Ken Barry <kb9888 gmail.com> writes:
Sorry, line

version(Win32): 

should read 

extern(Windows):
Aug 15 2008
prev sibling parent reply Lars Ivar Igesund <larsivar igesund.net> writes:
Ken Barry wrote:

 Just learning D, working with GLFW and dmd 1.030 on WinXP. The files
 glfw.d, gl.d and glu.d shipped with the GLFW distribution contain the
 following...
 
 version (Win32) {
     extern (Windows):
 }
 version (linux) {
     extern (C):
 }
 
 ...which results in Symbol Undefined errors.
 One of the files contains a variation...
 
 version(Win32)
    extern(Windows):
 else
    extern(C):
 
 ...which results in a syntax error on the 'else'.
 I have tried all the variations I can think of, such as
 
 version(Win32)
 {
    extern(Windows):
 }
 else
 {
    extern(C):
 }
 
 which also results in Symbol Undefined errors.
 The only thing that works is...
 
 version(Win32):
 
 ...on it's own. So I'm confused and would really appreciate it if anyone
 can explain this behaviour.
Behaviour in D changed at some point, so if you see examples/code that don't work, it is just too old. version (foo) { extern(something): } will only be applied to that version block, and so it won't apply to the symbols following below the version blocks. Either duplicate all symbols in each version block, or use extern (System): symbols ... System will then put in the correct extern depending on platform. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tango
Aug 15 2008
next sibling parent Ken Barry <kb9888 gmail.com> writes:
Lars Ivar Igesund Wrote:

 Behaviour in D changed at some point, so if you see examples/code that don't
 work, it is just too old.
 
 version (foo) {
 extern(something):
 }
 
 will only be applied to that version block, and so it won't apply to the
 symbols following below the version blocks. Either duplicate all symbols in
 each version block, or use
 
 extern (System):
  
 symbols ...
 
 System will then put in the correct extern depending on platform.
 
 -- 
 Lars Ivar Igesund
 blog at http://larsivi.net
 DSource, #d.tango & #D: larsivi
 Dancing the Tango
Thanks Lars, extern (System): works just fine :)
Aug 15 2008
prev sibling parent Ken Barry <kb9888 gmail.com> writes:
Lars Ivar Igesund Wrote:

 Behaviour in D changed at some point, so if you see examples/code that don't
 work, it is just too old.
 
 version (foo) {
 extern(something):
 }
 
 will only be applied to that version block, and so it won't apply to the
 symbols following below the version blocks. Either duplicate all symbols in
 each version block, or use
 
 extern (System):
  
 symbols ...
 
 System will then put in the correct extern depending on platform.
 
 -- 
 Lars Ivar Igesund
 blog at http://larsivi.net
 DSource, #d.tango & #D: larsivi
 Dancing the Tango
Thanks Lars, extern (System): works just fine :)
Aug 15 2008