digitalmars.D.learn - Purpose of template DECLARE_HANDLE in druntime
- Andre Pany (12/12) Jan 31 2019 Hi,
- Steven Schveighoffer (3/18) Jan 31 2019 Most likely it's a direct translation from a C preprocessor macro.
- Seb (5/17) Jan 31 2019 Have you tried changing it to alias and check whether the
- Adam D. Ruppe (15/18) Jan 31 2019 If my memory is correct, it is actually for old D compatibility.
- Kagamin (14/14) Jan 31 2019 It's a strong typed handle, in C it's declared as
- Andre Pany (8/22) Feb 01 2019 Thanks for all answers.
- Andre Pany (3/26) Feb 26 2019 Issue created
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
Jan 31 2019
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
Jan 31 2019
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 AndreHave 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.
Jan 31 2019
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?!
Jan 31 2019
It's a strong typed handle, in C it's declared as #ifdef STRICT typedef void *HANDLE; #if 0 && (_MSC_VER > 1000) #define #else #define #endif #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endif
Jan 31 2019
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 #else #define #endif #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endifThanks 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é
Feb 01 2019
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:Issue created https://issues.dlang.org/show_bug.cgi?id=19702It's a strong typed handle, in C it's declared as #ifdef STRICT typedef void *HANDLE; #if 0 && (_MSC_VER > 1000) #define #else #define #endif #else typedef PVOID HANDLE; #define DECLARE_HANDLE(name) typedef HANDLE name #endifThanks 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é
Feb 26 2019