Re: Purpose of template DECLARE_HANDLE in druntime

2019-02-26 Thread Andre Pany via Digitalmars-d-learn

On Friday, 1 February 2019 at 08:12:23 UTC, Andre Pany wrote:

On Friday, 1 February 2019 at 07:35:34 UTC, Kagamin wrote:

It's a strong typed handle, in C it's declared as

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct 
name##__ *name

#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; 
typedef struct name##__ *name

#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif


Thanks for all answers.
I understand, there was a reason in the past, but now
it is a superfluous construct.
I will create an issue and after that checks whether I can
create a pull request.

Kind regards
André


Issue created
https://issues.dlang.org/show_bug.cgi?id=19702



Re: Purpose of template DECLARE_HANDLE in druntime

2019-02-01 Thread Andre Pany via Digitalmars-d-learn

On Friday, 1 February 2019 at 07:35:34 UTC, Kagamin wrote:

It's a strong typed handle, in C it's declared as

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct 
name##__ *name

#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; 
typedef struct name##__ *name

#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif


Thanks for all answers.
I understand, there was a reason in the past, but now
it is a superfluous construct.
I will create an issue and after that checks whether I can
create a pull request.

Kind regards
André


Re: Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Kagamin via Digitalmars-d-learn

It's a strong typed handle, in C it's declared as

#ifdef STRICT
typedef void *HANDLE;
#if 0 && (_MSC_VER > 1000)
#define DECLARE_HANDLE(name) struct name##__; typedef struct 
name##__ *name

#else
#define DECLARE_HANDLE(name) struct name##__{int unused;}; 
typedef struct name##__ *name

#endif
#else
typedef PVOID HANDLE;
#define DECLARE_HANDLE(name) typedef HANDLE name
#endif


Re: Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 31 January 2019 at 20:51:37 UTC, Andre Pany wrote:

I noticed in druntime this template is used often:

package template DECLARE_HANDLE(string name, base = HANDLE) {
mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");


If my memory is correct, it is actually for old D compatibility. 
It used to do `version(D1) typedef, else alias`.


You can see in the code right above it that there is a commented 
struct and a usage of library Typedef too. A little bit further 
up is a comment about Typedef being because of new versions of D 
deprecating the keyword.


Old typedef fit the bill quite nicely, but it got deprecated and 
removed from the language. These headers used to be usable for 
various versions of D, and the mixin string lets you use keywords 
that no longer exist and centralize it a bit.



I don't think it tries to support old D any more, but I just 
don't believe anyone has wanted to change it. Programmers don't 
like to remove clever indirection tricks after writing them... 
what if you think of some better way to do it later?!


Re: Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Seb via Digitalmars-d-learn

On Thursday, 31 January 2019 at 20:51:37 UTC, Andre Pany wrote:

Hi,

I noticed in druntime this template is used often:

package template DECLARE_HANDLE(string name, base = HANDLE) {
mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");

The disadvantage is, IDEs like IntelliJ are not able to find 
the symbols using this template e.g.

mixin DECLARE_HANDLE!("SC_HANDLE");

What is the benefit of this template?
Why can't we just use
alias HANDLE SC_HANDLE;

Kind regards
Andre


Have you tried changing it to alias and check whether the 
testsuite still passes?
Druntime is a bit old, so I wouldn't be too surprised if this is 
an old relict.


Re: Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/31/19 3:51 PM, Andre Pany wrote:

Hi,

I noticed in druntime this template is used often:

package template DECLARE_HANDLE(string name, base = HANDLE) {
     mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");

The disadvantage is, IDEs like IntelliJ are not able to find the symbols 
using this template e.g.

mixin DECLARE_HANDLE!("SC_HANDLE");

What is the benefit of this template?
Why can't we just use
alias HANDLE SC_HANDLE;



Most likely it's a direct translation from a C preprocessor macro.

-Steve


Purpose of template DECLARE_HANDLE in druntime

2019-01-31 Thread Andre Pany via Digitalmars-d-learn

Hi,

I noticed in druntime this template is used often:

package template DECLARE_HANDLE(string name, base = HANDLE) {
mixin ("alias " ~ base.stringof ~ " " ~ name ~ ";");

The disadvantage is, IDEs like IntelliJ are not able to find the 
symbols using this template e.g.

mixin DECLARE_HANDLE!("SC_HANDLE");

What is the benefit of this template?
Why can't we just use
alias HANDLE SC_HANDLE;

Kind regards
Andre