Thread overview
Request for future
Dec 21, 2005
Vladislav Mazan
Dec 21, 2005
Walter Bright
Dec 21, 2005
Regan Heath
December 21, 2005
In practical programming using big libraries from C is to difficult (if there is no D wrapper/port, I must write many extern (C) statements, redefine #define IDENT int_value to const int IDENT = int_value; etc.). How about statement like this?

import (C) sys.time.h; // in C #include <sys/time.h>
import (C) .time.h;    // in C #include "time.h"
may be
import (C++) wx.h;

Second.
in post On Thu, 20 Oct 2005 23:20:50 +0400, Artem Rebrov <ar_other@mail.ru>
was wroted:
|#if(VerA>=4)
|  // do somethig
|#endif
|
|#if(VerA>=3)
|  // do somethig
|#endif
|
|#if(VerB>=2)
|  // do somethig
|#endif
|
|I can write:
|
|version(VerA_4)
|{ version=VerA_3;  version=VerA_2;}
|version(VerA_3)
|{ version=VerA_2;}
|version(VerB_4)
|{ version=VerB_3;  version=VerB_2;}
|version(VerB_3)
|{ version=VerB_2;}
|version(VerA_4)
|{/*do somethig*/}
|version(VerA_3)
|{/*do somethig*/}
|version(VerB_2)
|{/*do somethig*/}

This is a real problem for long-time live operation systems like FreeBSD and
Linuxes with 20 different versions with different versions of API.
I propose this syntax:

D                                                        C/C++
version(VerA)                                #ifdef VerA
{
}                                                    #endif


version(VerA >= 4)                        #if (VerA >= 4)
{
}                                                    #endif

version(VerA < 400 && VerA != 317)    #if (VerA < 400 && VerA != 317)
{
}                                                                #endif



December 21, 2005
Vladislav Mazan wrote:

> In practical programming using big libraries from C is to difficult (if there is no D wrapper/port, I must write many extern (C) statements, redefine #define IDENT int_value to const int IDENT = int_value; etc.). How about statement like this?
> 
> import (C) sys.time.h; // in C #include <sys/time.h>
> import (C) .time.h;    // in C #include "time.h"

D does not have the pre-processor, and is not source-compatible with C.

So while it would nice to have an offical tool that could translate most
headers, I don't think it will be available as a new compiler construct?

More likely a separate translator program, called something like "h2d".

> may be
> import (C++) wx.h;

D isn't link-compatible with C++ anyway, so that would not be as useful?


> Second.
[...]
> This is a real problem for long-time live operation systems like FreeBSD and Linuxes with 20 different versions with different versions of API.
> I propose this syntax:
> 
> D                                                        C/C++
> version(VerA)                                #ifdef VerA
> {
> }                                                    #endif
> 
> 
> version(VerA >= 4)                        #if (VerA >= 4)
> {
> }                                                    #endif
> 
> version(VerA < 400 && VerA != 317)    #if (VerA < 400 && VerA != 317)
> {
> }                                                                #endif

This has been suggested before... But I don't think the big W answered ?

http://www.digitalmars.com/d/archives/digitalmars/D/6883.html

http://www.digitalmars.com/d/archives/digitalmars/D/11946.html


Here is a real-life example on how the current kludge looks like:

version = GLUT_API_VERSION_1;
version = GLUT_API_VERSION_2;
version = GLUT_API_VERSION_3;

version = GLUT_XLIB_IMPLEMENTATION_1;
version = GLUT_XLIB_IMPLEMENTATION_2;
version = GLUT_XLIB_IMPLEMENTATION_3;
version = GLUT_XLIB_IMPLEMENTATION_4;
version = GLUT_XLIB_IMPLEMENTATION_5;
version = GLUT_XLIB_IMPLEMENTATION_7;
version = GLUT_XLIB_IMPLEMENTATION_8;
version = GLUT_XLIB_IMPLEMENTATION_9;
version = GLUT_XLIB_IMPLEMENTATION_11;
version = GLUT_XLIB_IMPLEMENTATION_12;
version = GLUT_XLIB_IMPLEMENTATION_13;
version = GLUT_XLIB_IMPLEMENTATION_14;
version = GLUT_XLIB_IMPLEMENTATION_15;

// some version combining logic cruft, until D gets version ops:

version (GLUT_API_VERSION_4)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_9;
version (GLUT_XLIB_IMPLEMENTATION_9)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_9;

version (GLUT_API_VERSION_4)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_11;
version (GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_11)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_11;

version (GLUT_API_VERSION_4)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_13;
version (GLUT_XLIB_IMPLEMENTATION_13)
	version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_13;

You gotta have a pretty liberal definition of "pretty",
for these kind of dirty D hacks to fit into it... :-)

--anders
December 21, 2005
"Anders F Björklund" <afb@algonet.se> wrote in message news:dob6d9$191g$1@digitaldaemon.com...
> version (GLUT_API_VERSION_4)
> version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_13;

The idea is to determine just what it is about v4 or v13 that is in common, and make a version identifier for that feature.

For example:

version (GLUT_API_VERSION_4)
{   version = HAS_FEATURE_X
     version = HAS_FEATURE_Y
}

version (GLUT_API_VERSION_13)
{   version = HAS_FEATURE_X
     version = HAS_FEATURE_Z
}


December 21, 2005
Walter Bright wrote:

>>version (GLUT_API_VERSION_4)
>>version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_13;
> 
> The idea is to determine just what it is about v4 or v13 that is in common, and make a version identifier for that feature.

Maybe I should have explained that I was just porting the GLUT
header file, and didn't really feel like investigating that :-)

(what you say sounds like good practice, when writing new code)

The original C code read:

#ifndef GLUT_API_VERSION  /* allow this to be overriden */
#define GLUT_API_VERSION		3
#endif

#ifndef GLUT_XLIB_IMPLEMENTATION  /* Allow this to be overriden. */
#define GLUT_XLIB_IMPLEMENTATION	15
#endif

#if (GLUT_API_VERSION >= 4 || GLUT_XLIB_IMPLEMENTATION >= 13)
#define GLUT_WINDOW_FORMAT_ID		((GLenum) 123)
#endif

--anders
December 21, 2005
On Wed, 21 Dec 2005 02:19:34 -0800, Walter Bright <newshound@digitalmars.com> wrote:
> "Anders F Björklund" <afb@algonet.se> wrote in message
> news:dob6d9$191g$1@digitaldaemon.com...
>> version (GLUT_API_VERSION_4)
>> version = GLUT_API_VERSION_4_or_GLUT_XLIB_IMPLEMENTATION_13;
>
> The idea is to determine just what it is about v4 or v13 that is in common, and make a version identifier for that feature.
>
> For example:
>
> version (GLUT_API_VERSION_4)
> {   version = HAS_FEATURE_X
>      version = HAS_FEATURE_Y
> }
>
> version (GLUT_API_VERSION_13)
> {   version = HAS_FEATURE_X
>      version = HAS_FEATURE_Z
> }

In general I agree. However, it makes a mechanical translation of C headers nearly impossible.

Regan