October 11, 2003
"Lars Ivar Igesund" <larsivi@stud.ntnu.no> wrote in message news:bm6lp2$qnl$1@digitaldaemon.com...
> Converting header files to D. If they are large and need different
> calling conventions on different platforms (like OpenGL), you need
> to write all the declarations twice. (Unless Walter make it possible
> to alias the calling conventions. Then I could put just the alias in a
> version statement.)

How about this:

version (Foo)
{
    extern (C):
}
version (Bar)
{
    extern (Windows):
}

void abc();
void def();
...


October 11, 2003
You could also write:

version (Windows)
{
    char[] Drive();
}
else
{
    char[] Drive() { return ""; }
}

"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bm7k39$244a$1@digitaldaemon.com...
> No, but consider this, latest, one:
>
>             char[]  composite_path1 =   null
> version(Windows)
> {
>                                     ~   Drive()
> } // version(Windows)
>                                     ~   Directory()
>                                     ~   File()
>                                     ;
>
> No-one can tell me that this would be better written as
>
> version(Windows)
> {
>             char[]  composite_path1 =   null
>                                     ~   Drive()
>                                     ~   Directory()
>                                     ~   File()
>                                     ;
> }
> else
> {
>             char[]  composite_path1 =   null
>                                     ~   Directory()
>                                     ~   File()
>                                     ;
> } // version(Windows)
>
> Now I have to write it as
>
>             char[]  composite_path1 =   null;
> version(Windows)
> {
>                     composite_path1 ~=  Drive();
> } // version(Windows)
>                     composite_path1 ~=  Directory();
>                     composite_path1 ~=  File();
>
> While this may be fine in the current context - inside an invariant - it would be undesirable in release code. Maybe repeated ~= are less efficient that a single ~, as they are in some other languages. Even if they're not,
I
> disagree that this repression of expressiveness is a good thing, just because it is easier to implement the language feature in this way.
>
>
>
> "Jan-Eric Duden" <jeduden@whisset.com> wrote in message news:bm65lf$58d$1@digitaldaemon.com...
> > I guess we  need to get rid of our old "macro" habbits and rethink. :) Or do you have a problem where version won't work at all?
> >
> > --
> > Jan-Eric Duden
> > "Matthew Wilson" <matthew@stlsoft.org> wrote in message
> > news:bm64m2$3ue$1@digitaldaemon.com...
> > > Yeah, that was not the best example. But that doesn't detract from the general thrust of my argument. If the version-dependent code is not
> > cleanly
> > > outside a { } scope, then it breaks. Which sucks, and is unnecessarily restrictive
> > >
> > > "Daniel Yokomiso" <daniel_yokomiso@yahoo.com.br> wrote in message news:bm62lk$18a$1@digitaldaemon.com...
> > > > "Matthew Wilson" <matthew@stlsoft.org> escreveu na mensagem news:bm60qd$30eh$1@digitaldaemon.com...
> > > > > version(Windows)
> > > > > {
> > > > >             recls_assert(0 == strcmp(path + 2, pathCheck));
> > > > >             if(0 != strcmp(path + 2, pathCheck))
> > > > > }  <== HERE
> > > > > else
> > > > > {
> > > > >             recls_assert(0 == strcmp(path, pathCheck));
> > > > >             if(0 != strcmp(path, pathCheck))
> > > > > }
> > > > >             {
> > > > >                 fprintf(stderr, "Path is different from path
> > > > > components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);
> > > > >
> > > > >                 abort();
> > > > >             }
> > > > >
> > > > >
> > > > > This does not compile. Understandably, the compiler doesn't like
the
> > > brace
> > > > > indicated. What are my options? Do I have to include the body of
the
> > if
> > > > > statement twice? That doesn't help maintainability, does it?
> > > > >
> > > > > I think version should either use a different brace, or should use
a
> > > > > different format altogether. Otherwise we'll be decreasing
> > > > maintainability,
> > > > > rather than increasing it.
> > > > >
> > > > > Harummpphh!
> > > >
> > > > Why don't you just write:
> > > >
> > > >
> > > > path2 = path;
> > > > version(Windows)
> > > > {
> > > >     path2 = path2 + 2;
> > > > }
> > > >             recls_assert(0 == strcmp(path2, pathCheck));
> > > >             if(0 != strcmp(path2, pathCheck))
> > > >             {
> > > >                 fprintf(stderr, "Path is different from path
> > > > components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);
> > > >
> > > >                 abort();
> > > >             }
> > > >
> > > >
> > > > It'll remove the duplicated code and do what it's supposed to do.
When
> I
> > > saw
> > > > your example the first thing in my head was "why the code is
duplicate
> d,
> > > > there must be another difference besides the '+ 2'." so I read the
> code
> > > > carefully and discovered it was ok. If I was the maintainance
> programmer
> > I
> > > > would question that. IME it's better to reduce the differences to
the
> > > > absolute minimum, so it'll be clear what must be equal and what must
> be
> > > > different.
> > > >
> > > > Best regards,
> > > > Daniel Yokomiso.
> > > >
> > > > "The difference between me and the other surrealists is that I'm a
> > > > surrealist."
> > > >  - Dali
> > > >
> > > >
> > > > ---
> > > > Outgoing mail is certified Virus Free.
> > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
> > > >
> > > >
> > >
> > >
> >
> >
>
>


October 11, 2003
"Walter" <walter@digitalmars.com> wrote in message news:bm9ree$2468$2@digitaldaemon.com...
>
> "Lars Ivar Igesund" <larsivi@stud.ntnu.no> wrote in message news:bm6lp2$qnl$1@digitaldaemon.com...
> > Converting header files to D. If they are large and need different
> > calling conventions on different platforms (like OpenGL), you need
> > to write all the declarations twice. (Unless Walter make it possible
> > to alias the calling conventions. Then I could put just the alias in a
> > version statement.)
>
> How about this:
>
> version (Foo)
> {
>     extern (C):
> }
> version (Bar)
> {
>     extern (Windows):
> }
>
> void abc();
> void def();
> ...

Looks ok to me. I'll test it some other day.

Lars Ivar Igesund


October 11, 2003
No! On operating systems that do not have a drive, it is absolutely bogus and evil to give them a "null" drive.

(btw, Drive returns a char, not a string)

Anyway, that's just the specific case. This will come up time and time again, probably almost as much as #define is used, so we need something that works.

"Walter" <walter@digitalmars.com> wrote in message news:bm9ref$2468$3@digitaldaemon.com...
> You could also write:
>
> version (Windows)
> {
>     char[] Drive();
> }
> else
> {
>     char[] Drive() { return ""; }
> }
>
> "Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bm7k39$244a$1@digitaldaemon.com...
> > No, but consider this, latest, one:
> >
> >             char[]  composite_path1 =   null
> > version(Windows)
> > {
> >                                     ~   Drive()
> > } // version(Windows)
> >                                     ~   Directory()
> >                                     ~   File()
> >                                     ;
> >
> > No-one can tell me that this would be better written as
> >
> > version(Windows)
> > {
> >             char[]  composite_path1 =   null
> >                                     ~   Drive()
> >                                     ~   Directory()
> >                                     ~   File()
> >                                     ;
> > }
> > else
> > {
> >             char[]  composite_path1 =   null
> >                                     ~   Directory()
> >                                     ~   File()
> >                                     ;
> > } // version(Windows)
> >
> > Now I have to write it as
> >
> >             char[]  composite_path1 =   null;
> > version(Windows)
> > {
> >                     composite_path1 ~=  Drive();
> > } // version(Windows)
> >                     composite_path1 ~=  Directory();
> >                     composite_path1 ~=  File();
> >
> > While this may be fine in the current context - inside an invariant - it would be undesirable in release code. Maybe repeated ~= are less
efficient
> > that a single ~, as they are in some other languages. Even if they're
not,
> I
> > disagree that this repression of expressiveness is a good thing, just because it is easier to implement the language feature in this way.
> >
> >
> >
> > "Jan-Eric Duden" <jeduden@whisset.com> wrote in message news:bm65lf$58d$1@digitaldaemon.com...
> > > I guess we  need to get rid of our old "macro" habbits and rethink. :) Or do you have a problem where version won't work at all?
> > >
> > > --
> > > Jan-Eric Duden
> > > "Matthew Wilson" <matthew@stlsoft.org> wrote in message
> > > news:bm64m2$3ue$1@digitaldaemon.com...
> > > > Yeah, that was not the best example. But that doesn't detract from
the
> > > > general thrust of my argument. If the version-dependent code is not
> > > cleanly
> > > > outside a { } scope, then it breaks. Which sucks, and is
unnecessarily
> > > > restrictive
> > > >
> > > > "Daniel Yokomiso" <daniel_yokomiso@yahoo.com.br> wrote in message news:bm62lk$18a$1@digitaldaemon.com...
> > > > > "Matthew Wilson" <matthew@stlsoft.org> escreveu na mensagem news:bm60qd$30eh$1@digitaldaemon.com...
> > > > > > version(Windows)
> > > > > > {
> > > > > >             recls_assert(0 == strcmp(path + 2, pathCheck));
> > > > > >             if(0 != strcmp(path + 2, pathCheck))
> > > > > > }  <== HERE
> > > > > > else
> > > > > > {
> > > > > >             recls_assert(0 == strcmp(path, pathCheck));
> > > > > >             if(0 != strcmp(path, pathCheck))
> > > > > > }
> > > > > >             {
> > > > > >                 fprintf(stderr, "Path is different from path
> > > > > > components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);
> > > > > >
> > > > > >                 abort();
> > > > > >             }
> > > > > >
> > > > > >
> > > > > > This does not compile. Understandably, the compiler doesn't like
> the
> > > > brace
> > > > > > indicated. What are my options? Do I have to include the body of
> the
> > > if
> > > > > > statement twice? That doesn't help maintainability, does it?
> > > > > >
> > > > > > I think version should either use a different brace, or should
use
> a
> > > > > > different format altogether. Otherwise we'll be decreasing
> > > > > maintainability,
> > > > > > rather than increasing it.
> > > > > >
> > > > > > Harummpphh!
> > > > >
> > > > > Why don't you just write:
> > > > >
> > > > >
> > > > > path2 = path;
> > > > > version(Windows)
> > > > > {
> > > > >     path2 = path2 + 2;
> > > > > }
> > > > >             recls_assert(0 == strcmp(path2, pathCheck));
> > > > >             if(0 != strcmp(path2, pathCheck))
> > > > >             {
> > > > >                 fprintf(stderr, "Path is different from path
> > > > > components\n\tpath:  %.*s\n\tparts: %.*s\n\n", path, pathCheck);
> > > > >
> > > > >                 abort();
> > > > >             }
> > > > >
> > > > >
> > > > > It'll remove the duplicated code and do what it's supposed to do.
> When
> > I
> > > > saw
> > > > > your example the first thing in my head was "why the code is
> duplicate
> > d,
> > > > > there must be another difference besides the '+ 2'." so I read the
> > code
> > > > > carefully and discovered it was ok. If I was the maintainance
> > programmer
> > > I
> > > > > would question that. IME it's better to reduce the differences to
> the
> > > > > absolute minimum, so it'll be clear what must be equal and what
must
> > be
> > > > > different.
> > > > >
> > > > > Best regards,
> > > > > Daniel Yokomiso.
> > > > >
> > > > > "The difference between me and the other surrealists is that I'm a
> > > > > surrealist."
> > > > >  - Dali
> > > > >
> > > > >
> > > > > ---
> > > > > Outgoing mail is certified Virus Free.
> > > > > Checked by AVG anti-virus system (http://www.grisoft.com).
> > > > > Version: 6.0.524 / Virus Database: 321 - Release Date: 7/10/2003
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>


October 12, 2003
> How about this:
> 
> version (Foo)
> {
>     extern (C):
> }
> version (Bar)
> {
>     extern (Windows):
> }
> 
> void abc();
> void def();
> ...

Does it work good? I performed a simple following experiment:

> cat version.d
version (C) {
        extern(C):
        void c_func() {}
} // I think "extern (C)" is ended.
void maybe_not_c_func() {}
> dmd -c version.d
> nm version.o
00000000 ? _D7version16maybe_not_c_funcFZv
00000000 t gcc2_compiled.
> dmd -c -version=C version.d
> nm version.o
00000000 ? _D7version16maybe_not_c_funcFZv
00000000 ? c_func
00000000 t gcc2_compiled.

I hope the last maybe_not_c_func has C-linkage, but it has D-linkage in my environment (Linux, DMD-0.73).

------------------
 shinichiro.h
  s31552@mail.ecc.u-tokyo.ac.jp

October 13, 2003


---

Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09


October 13, 2003


---

Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09


October 13, 2003
"Jan-Eric Duden" <jeduden@whisset.com> wrote in message
news:bm65lf$58d$1@digitaldaemon.com...
| I guess we  need to get rid of our old "macro" habbits and rethink. :)
| Or do you have a problem where version won't work at all?
|
| --
| Jan-Eric Duden

(Sorry for that previous one)

I believe that's something that happens when we all go from one language to another.

—————————————————————————
Carlos Santander
"Jan-Eric Duden" <jeduden@whisset.com> wrote in message
news:bm65lf$58d$1@digitaldaemon.com...
| I guess we  need to get rid of our old "macro" habbits and rethink. :)
| Or do you have a problem where version won't work at all?
|
| --
| Jan-Eric Duden

(Sorry for that previous one)

I believe that's something that happens when we all go from one language to another.

————————————————————————— Carlos Santander


October 13, 2003
"Nicolas Repiquet" <deadcow-remove-this@free.fr> wrote in message
news:bm66gs$68l$1@digitaldaemon.com...
|
|
|   recls_assert(0 == strcmp(path + ( version(Windows) ? 0 : 2 ),
pathCheck));
|   if(0 != strcmp(path + ( version(Windows) ? 0 : 2 ), pathCheck))
|   {
|     fprintf(stderr, "Path is different from path ..." );
|     abort();
|   }
|
|

(Sorry for that one too)

I also like that.

————————————————————————— Carlos Santander


---

Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.525 / Virus Database: 322 - Release Date: 2003-10-09


October 14, 2003
"Matthew Wilson" <matthew@stlsoft.org> wrote in message news:bm9sds$25dr$1@digitaldaemon.com...
> No! On operating systems that do not have a drive, it is absolutely bogus and evil to give them a "null" drive.
>
> (btw, Drive returns a char, not a string)
>
> Anyway, that's just the specific case. This will come up time and time again, probably almost as much as #define is used, so we need something
that
> works.

I know what you mean. Where I'm coming from is that I have dealt a lot with code that had lots of deeply embedded #ifdef's in it that are pushed down to the lowest level possible. I eventually came to the conclusion that #ifdef's should be at a higher level (makes the code much easier to read). Perhaps it's at too high a level with version, but I want to give it a try and see how it goes.