Re: Why does this work?
On Tuesday, 24 June 2014 at 10:11:05 UTC, bearophile wrote: I don't think it's solved. There are probably bugs worth reporting here. I have not found them, sorry for the noise. Bye, bearophile This looks really bad. I thought we weren't going to allow variable templates, just enums and aliases?
Re: Why does this work?
I don't think it's solved. There are probably bugs worth reporting here. I have not found them, sorry for the noise. Bye, bearophile
Re: Why does this work?
h_zet: Problem solved, Thank you so much! I don't think it's solved. There are probably bugs worth reporting here. Bye, bearophile
Re: Why does this work?
On Monday, 23 June 2014 at 09:09:56 UTC, hane wrote: On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" } Problem solved, Thank you so much!
Re: Why does this work?
h_zet: Why does this work? Or it is a bug? When you play a little with this code it's easy to see _error_ that should not appear. So there's surely something worth reporting as bug, but I don't yet know what. Bye, bearophile
Re: Why does this work?
On Monday, 23 June 2014 at 09:29:15 UTC, Mason McGill wrote: Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. } It looks like I'm mistaken. Variable templates are supposed to exist. Please ignore the previous post.
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? Strange behavior, indeed. It took me a minute, but I think I know what's going on, and I'm pretty sure it's a bug. D recently introduced a short syntax for function-like templates: enum a(b) = "some_value"; It looks like this also (sort of) works with other qualifiers, which I believe it shouldn't. Here's a minimal example that might be good to put in a bug report: void main() { enum a(x) = "some_value"; // Good. auto b(x) = "some_value"; // Huh? // This also works for `const`, `static`, etc. }
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? You declared a variable template named "tuple" (with unused type parameters a, b) on that line. http://dlang.org/template.html#variable-template I think this is very confusable syntax... void main() { auto tuple(a, b) = foo2(1); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1, true)" tuple!(int, int) = foo2(20); writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20, true)" }
Re: Why does this work?
On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote: import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug? Looks grammaticallyu correct: R type is guessed/infered from the parameter
Why does this work?
import std.typecons; auto foo2(R)(R foopara){ return tuple(foopara, is(R==int)); } void main(){ auto tuple(a,b) = foo2(1); } I'm expecting some error such as can not act as left value but when I compiled this, no error occured. DMD version is DMD64 v2.065.(ldc2 exited with error function declaration without return type) Why does this work? Or it is a bug?
Re: Why does this work?
On Sat, Jan 24, 2009 at 8:38 PM, Mike L. wrote: > > Thanks for your response. Could you tell me what the compiler is linking to > that contains GetEnvironmentStringsA() (and others) and how the compiler > knows to do this? > It's in either user32 or kernel32, and I think DMD always links against them (since virtually every program on Windows needs to).
Re: Why does this work?
Denis Koroskin Wrote: > Mike L. Wrote: > > > I saved and compiled the code given as getenv.d on the page > > http://www.digitalmars.com/d/archives/digitalmars/D/learn/623.html but I'm > > not entirely sure why it works. > > > > The reasons that I don't understand it are: > > 1. GetEnvironmentStringsA() and the other functions aren't mentioned in > > std/c/windows/windows.d . > > It is not defined int std.c.windows.windows, that's why it is defined in the > code itself: > > # // function retrieves the environment variables for the current process. > # extern( Windows ) LPVOID GetEnvironmentStringsA(); > # > > > and I can compile it with a simple "dmd getenv.d" without passing any other > > object files or libraries. If it's not in windows.d, why is windows.d even > > imported? > > > > std.c.windows.windows is imported so that compiler knows about LPSTR, LPVOID, > BOOL etc. > > > 2. MSDN says that GetEnvironmentStringsA() returns LPTCH but getenv.d's > > version returns LPVOID. > > That's true, you should update function's return type and remove unneccessary > casts: > > extern( Windows ) LPTSTR GetEnvironmentStringsA(); > ... > for (lpszVariable = lpvEnv; *lpszVariable; lpszVariable++) Thanks for your response. Could you tell me what the compiler is linking to that contains GetEnvironmentStringsA() (and others) and how the compiler knows to do this?
Re: Why does this work?
Mike L. Wrote: > I saved and compiled the code given as getenv.d on the page > http://www.digitalmars.com/d/archives/digitalmars/D/learn/623.html but I'm > not entirely sure why it works. > > The reasons that I don't understand it are: > 1. GetEnvironmentStringsA() and the other functions aren't mentioned in > std/c/windows/windows.d . It is not defined int std.c.windows.windows, that's why it is defined in the code itself: # // function retrieves the environment variables for the current process. # extern( Windows ) LPVOID GetEnvironmentStringsA(); # > and I can compile it with a simple "dmd getenv.d" without passing any other > object files or libraries. If it's not in windows.d, why is windows.d even > imported? > std.c.windows.windows is imported so that compiler knows about LPSTR, LPVOID, BOOL etc. > 2. MSDN says that GetEnvironmentStringsA() returns LPTCH but getenv.d's > version returns LPVOID. That's true, you should update function's return type and remove unneccessary casts: extern( Windows ) LPTSTR GetEnvironmentStringsA(); ... for (lpszVariable = lpvEnv; *lpszVariable; lpszVariable++)
Why does this work?
I saved and compiled the code given as getenv.d on the page http://www.digitalmars.com/d/archives/digitalmars/D/learn/623.html but I'm not entirely sure why it works. The reasons that I don't understand it are: 1. GetEnvironmentStringsA() and the other functions aren't mentioned in std/c/windows/windows.d . and I can compile it with a simple "dmd getenv.d" without passing any other object files or libraries. If it's not in windows.d, why is windows.d even imported? 2. MSDN says that GetEnvironmentStringsA() returns LPTCH but getenv.d's version returns LPVOID.