Re: struct constructor co nfusion
On 06.11.2015 20:05, Spacen Jasset wrote: Also, I had to add a dummy private constructor to make my structs 'createable', or is there another way? e.g. struct Texture { @disable this(); static Texture create() { return Texture(0); } ... private: this(int) { glGenTextures(1, &textureId_); enforce(0 != textureId_); } GLuint textureId_; } You can use Texture.init to initialize a variable: struct Texture { @disable this(); static Texture create() { Texture t = Texture.init; glGenTextures(1, &t.textureId_); enforce(0 != t.textureId_); return t; } private: GLuint textureId_; }
Re: Align a variable on the stack.
On Saturday, 7 November 2015 at 03:18:59 UTC, steven kladitis wrote: [...] I am still disappointed that DMD is not native 64 bit in windows yet. [...] It's because they can't make a nice distribution. DMD win32 is a nice package that works out of the box (compiler, standard C lib, standard D lib, linker, etc) without any further configuration or derquirement. DMD win64 requires MSVS for the standard C lib and the linker.
Re: method has no return statement with switch
On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: [...] url.Cache.UrlCache.doRequest has no return statement, but is expected to return a value of type string [...] public string doRealRequest(string url, Method method) You posted the wrong code sample: your code shows doRealRequest but the message is about doRequest !
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 04:25:00 UTC, Mike Parker wrote: Missed this in my previous reply. No problem. I appreciate you taking the time to help me either way :)
Re: method has no return statement with switch
On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: Hi! I have the error message: source/url.cache.d(20,16): Error: function url.Cache.UrlCache.doRequest has no return statement, but is expected to return a value of type string [...] Because the "switch" is marked as "final", eventually one of cases will be followed. Because both cases have a "return" point, code will never get out of switch statement. So the compiler acts correctly.
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: I went to std.bitmanip to look for unittests using the Endian, and the only one that does uses read!(T, endianness), which needs endianness to be known at compile time, which I don't have. Missed this in my previous reply.
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For basic testing I'm just trying to use: read!double(endianess, ubyteArr).writeln; endianess is an Endian from std.system, and ubyteArr is an 8 byte ubyte[]. When I run this I get: Error: template std.bitmanip.read cannot deduce function from argument types !(double)(Endian, ubyte[]), candidates are: std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) dmd failed with exit code 1. You're passing endianess as a function argument, but the signatures in the error says it's supposed to be a template argument. Did you try this? read!(double, endianess)(ubyteArr);
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 03:53:14 UTC, Nicholas Wilson wrote: On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For basic testing I'm just trying to use: read!double(endianess, ubyteArr).writeln; endianess is an Endian from std.system, and ubyteArr is an 8 byte ubyte[]. When I run this I get: Error: template std.bitmanip.read cannot deduce function from argument types !(double)(Endian, ubyte[]), candidates are: std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) dmd failed with exit code 1. Clearly that didn't work, so I tried excluding the endianess: read!double(ubyteArr).writeln; and that does work! But its the wrong byte order, so its incorrect anyways. I went to std.bitmanip to look for unittests using the Endian, and the only one that does uses read!(T, endianness), which needs endianness to be known at compile time, which I don't have. Any suggestions? Cheat! T read(T,R)(Endian endianness , R r) { if(endianness == Endian.bigEndian) return std.bitmanip.read!(T,Endian.bigEndian,R)(r); else if (endianness == Endian.littleEndian) return std.bitmanip.read!(T,Endian.littleEndian,R)(r); } Thanks! but... you are on a little endian system (bigEndian gave wrong byte order ) The actual use case is reading a binary file of unknown endianness. I don't think I'm that fortunate sadly.
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For basic testing I'm just trying to use: read!double(endianess, ubyteArr).writeln; endianess is an Endian from std.system, and ubyteArr is an 8 byte ubyte[]. When I run this I get: Error: template std.bitmanip.read cannot deduce function from argument types !(double)(Endian, ubyte[]), candidates are: std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) dmd failed with exit code 1. Clearly that didn't work, so I tried excluding the endianess: read!double(ubyteArr).writeln; and that does work! But its the wrong byte order, so its incorrect anyways. I went to std.bitmanip to look for unittests using the Endian, and the only one that does uses read!(T, endianness), which needs endianness to be known at compile time, which I don't have. Any suggestions? Cheat! T read(T,R)(Endian endianness , R r) { if(endianness == Endian.bigEndian) return std.bitmanip.read!(T,Endian.bigEndian,R)(r); else if (endianness == Endian.littleEndian) return std.bitmanip.read!(T,Endian.littleEndian,R)(r); } but... you are on a little endian system (bigEndian gave wrong byte order ) you don't need to use bitmanip.read type repainting will work. ubyte[] r = [ /* ... */ ]; double d = *cast(double*)r.ptr;
Re: question about using std.bitmanip.read
On Saturday, 7 November 2015 at 03:19:44 UTC, Charles wrote: Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For basic testing I'm just trying to use: read!double(endianess, ubyteArr).writeln; endianess is an Endian from std.system, and ubyteArr is an 8 byte ubyte[]. When I run this I get: Error: template std.bitmanip.read cannot deduce function from argument types !(double)(Endian, ubyte[]), candidates are: std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) dmd failed with exit code 1. Clearly that didn't work, so I tried excluding the endianess: read!double(ubyteArr).writeln; and that does work! But its the wrong byte order, so its incorrect anyways. I went to std.bitmanip to look for unittests using the Endian, and the only one that does uses read!(T, endianness), which needs endianness to be known at compile time, which I don't have. Any suggestions? You must create a classic run-time branch: --- if(endianess == Endian.bigEndian) read!(Endian.bigEndian, double)(ubyteArr).writeln; else read!(Endian.littleEndian, double)(ubyteArr).writeln; --- or in the same fashion use a final switch.
question about using std.bitmanip.read
Hi guys, It's me again... still having some issues pop up getting started, but I remain hopeful I'll stop needing to ask so many questions soon. I'm trying to use std.bitmanip.read; however, am having some issues using it. For basic testing I'm just trying to use: read!double(endianess, ubyteArr).writeln; endianess is an Endian from std.system, and ubyteArr is an 8 byte ubyte[]. When I run this I get: Error: template std.bitmanip.read cannot deduce function from argument types !(double)(Endian, ubyte[]), candidates are: std.bitmanip.read(T, Endian endianness = Endian.bigEndian, R)(ref R range) if (canSwapEndianness!T && isInputRange!R && is(ElementType!R : const(ubyte))) dmd failed with exit code 1. Clearly that didn't work, so I tried excluding the endianess: read!double(ubyteArr).writeln; and that does work! But its the wrong byte order, so its incorrect anyways. I went to std.bitmanip to look for unittests using the Endian, and the only one that does uses read!(T, endianness), which needs endianness to be known at compile time, which I don't have. Any suggestions?
Re: Align a variable on the stack.
On Friday, 6 November 2015 at 01:17:20 UTC, TheFlyingFiddle wrote: On Friday, 6 November 2015 at 00:43:49 UTC, rsw0x wrote: On Thursday, 5 November 2015 at 23:37:45 UTC, TheFlyingFiddle wrote: On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle wrote: [...] I reduced it further: [...] these run at the exact same speed for me and produce identical assembly output from a quick glance dmd 2.069, -O -release -inline Are you running on windows? I tested on windows x64 and there I also get the exact same speed for both functions. I am still disappointed that DMD is not native 64 bit in windows yet. Please show exactly how you are getting 64 bit to work in windows 10. I have never gotten this to work. for any version of DMD. All of my new $400.00 systems are 4 gig 64 bit windows 10...and the processor instruction sets are very nice. I dabble in assembler. I have always wondered why D does not take advantage of newer instructions.. and 64 bit. I see a 64 Bit droid Compiler for D. :):):)
Re: Operator implicit conversion difference
On Saturday, 7 November 2015 at 01:10:01 UTC, Ali Çehreli wrote: On 11/06/2015 04:56 PM, BBaz wrote: On Thursday, 5 November 2015 at 13:20:26 UTC, ixid wrote: [...] What's inconsistent is the integral promotion of the add expression result that stops from 4 bytes int: --- int a, b; a += b; a = a + b; --- is compiled but according to the specs, a + b result should be widened to long: http://dlang.org/expression.html#AddExpression (ubyte, byte) until (uint int) should be widened and (long , ulong) wrapped. This behavior would match the specs better. You say 'long' but according to integer promotions, a and b should both be promoted to 'int' and the result of 'a + b' is int: http://dlang.org/type.html#integer-promotions Ali oh...sorry I thought that the widening was done to the follwing type that's bigger, eg byte->short, short->int. So no inconsistence at all.
Re: Operator implicit conversion difference
On 11/06/2015 04:56 PM, BBaz wrote: On Thursday, 5 November 2015 at 13:20:26 UTC, ixid wrote: This may have been overlooked in my other thread so I wanted to ask again: This seems very inconsistent, does a += b not lower to a = a + b? I guess not based on the below: ushort a = ushort.max, b = ushort.max; a += b; // Compiles fine a = a + b; // Error: cannot implicitly convert expression (cast(int)a + cast(int)b) of type int to ushort What's inconsistent is the integral promotion of the add expression result that stops from 4 bytes int: --- int a, b; a += b; a = a + b; --- is compiled but according to the specs, a + b result should be widened to long: http://dlang.org/expression.html#AddExpression (ubyte, byte) until (uint int) should be widened and (long , ulong) wrapped. This behavior would match the specs better. You say 'long' but according to integer promotions, a and b should both be promoted to 'int' and the result of 'a + b' is int: http://dlang.org/type.html#integer-promotions Ali
Re: method has no return statement with switch
On Saturday, 7 November 2015 at 00:30:29 UTC, crimaniak wrote: On Saturday, 7 November 2015 at 00:27:02 UTC, Adam D. Ruppe wrote: On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: Inserting dummy return statement doesn't help. final switch / switch with default - no matter. Try inserting assert(0); instead of a dummy return. Done, no difference. Wow, that impossible. You switch is well final. here DMD 2.068, linux x86_64 the folling compiles and runs: enum Method { GET="GET", POST="POST" } class UrlCache { public string doRealRequest(string url, Method method) { final switch(method) { case Method.GET: return std.net.curl.get!AutoProtocol(url).idup; case Method.POST: return std.net.curl.post(url, []).idup; } } } void main() {auto test = new UrlCache;} are you sure that the error you get doesnt come from another location ?!
Re: Operator implicit conversion difference
On Thursday, 5 November 2015 at 13:20:26 UTC, ixid wrote: This may have been overlooked in my other thread so I wanted to ask again: This seems very inconsistent, does a += b not lower to a = a + b? I guess not based on the below: ushort a = ushort.max, b = ushort.max; a += b; // Compiles fine a = a + b; // Error: cannot implicitly convert expression (cast(int)a + cast(int)b) of type int to ushort What's inconsistent is the integral promotion of the add expression result that stops from 4 bytes int: --- int a, b; a += b; a = a + b; --- is compiled but according to the specs, a + b result should be widened to long: http://dlang.org/expression.html#AddExpression (ubyte, byte) until (uint int) should be widened and (long , ulong) wrapped. This behavior would match the specs better.
Re: method has no return statement with switch
On Saturday, 7 November 2015 at 00:27:02 UTC, Adam D. Ruppe wrote: On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: Inserting dummy return statement doesn't help. final switch / switch with default - no matter. Try inserting assert(0); instead of a dummy return. Done, no difference.
Re: method has no return statement with switch
On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: Inserting dummy return statement doesn't help. final switch / switch with default - no matter. Try inserting assert(0); instead of a dummy return.
Re: opCmp with structs
On Friday, 6 November 2015 at 22:55:15 UTC, Alex wrote: Ok... the question is not silly any more... without 'immutable' it works. So, what am I missing? sorry, again a forum bug that stripped my answer: sort() fails because in the template constraint `hasAssignableElements` fails. hasAssignableElements fails because of this you cannot assign another value to a ku because the immutable member is already defined. --- template hasAssignableElements(R) { enum bool hasAssignableElements = isInputRange!R && is(typeof( (inout int = 0) { R r = R.init; r.front = r.front; static if (isBidirectionalRange!R) r.back = r.front; static if (isRandomAccessRange!R) r[0] = r.front; })); } --- more especially this is 'r.front = r.front;' that doesn't pass: --- import std.range; struct ku { immutable int id; } void main() { ku[] tt; tt.front = tt.front; } --- so yeah, it cant work if id is immutable.
method has no return statement with switch
Hi! I have the error message: source/url.cache.d(20,16): Error: function url.Cache.UrlCache.doRequest has no return statement, but is expected to return a value of type string Inserting dummy return statement doesn't help. final switch / switch with default - no matter. As I understand compiler must detect when end of function is unreachable (and in fact it detects it - see comment about return ""; line) and do not try to check for return value. Is this my or compiler's error here? dmd --version DMD64 D Compiler v2.069.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright [code] module url.Cache; import std.conv; import core.exception; import mysql.d; import std.digest.md; import std.net.curl; enum Method { GET="GET", POST="POST" } class UrlCache { // ... public string doRealRequest(string url, Method method) { final switch(method) { case Method.GET: return std.net.curl.get!AutoProtocol(url).text; case Method.POST: return std.net.curl.post(url, []).text; } // return ""; // produces 'statement is not reachable' warning, don't fix the problem } // ... } [/code]
Re: opCmp with structs
On Friday, 6 November 2015 at 22:55:15 UTC, Alex wrote: Ok... the question is not silly any more... without 'immutable' it works. So, what am I missing? sort() fails because in the template constraint `hasAssignableElements
Re: opCmp with structs
On 11/06/2015 02:54 PM, Alex wrote: > I'm sure I'm doing a silly mistake somewhere, but why this doesn't work? > import std.stdio; > import std.algorithm; > > struct ku > { > immutable int id; > alias id this; > > this(int i) > { > id = i; > } > > int opCmp(ref const ku rhs) const {return id - rhs.id; } > } > > void main() > { > ku[] tt = [ku(2), ku(1)]; > sort(tt); > } Continuing from your hint: So, opCmp works but it is sort() that cannot move objects of ku around because of that immutable variable. There may be references to ku objects or its id members and those references may be depending on the immutability of that member. const and immutable members effectively make objects unassignable. (const part is the same in C++.) Ali
Re: opCmp with structs
Ok... the question is not silly any more... without 'immutable' it works. So, what am I missing?
opCmp with structs
I'm sure I'm doing a silly mistake somewhere, but why this doesn't work? import std.stdio; import std.algorithm; struct ku { immutable int id; alias id this; this(int i) { id = i; } int opCmp(ref const ku rhs) const {return id - rhs.id; } } void main() { ku[] tt = [ku(2), ku(1)]; sort(tt); }
Re: Working Windows GUI library - no console Window
On Friday, 6 November 2015 at 21:02:59 UTC, John Chapman wrote: On Friday, 6 November 2015 at 15:52:10 UTC, johann wrote: hi, i like to use a window gui library and i think i found a working one. https://github.com/FrankLIKE/dfl2 - works with x64 the problem is, that with DMD 2.069.0, VS2015 and visualD the trick of using "-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup" does not suppress the console window anymore. does anybody have a solution for that problem? is anybody still working on that library? johann Same problem here. I had to remove the mainCRTStartup flag and use WinMain as my entry point. me too. i need to start a main(), since the lib will not work with a starting WinMain.
Re: Align a variable on the stack.
On Friday, 6 November 2015 at 17:55:47 UTC, arGus wrote: I did some testing on Linux and Windows. I ran the code with ten times the iterations, and found the results consistent with what has previously been observed in this thread. The code seems to run just fine on Linux, but is slowed down 10x on Windows x86. Windows (32-bit) rdmd bug.d -inline -boundscheck=off -release Default: TickDuration(14398890) Explicit: TickDuration(16) Linux (64-bit) rdmd bug.d -m64 -inline -boundscheck=off Default: TickDuration(59090876) Explicit: TickDuration(49529493) Linux (32-bit) rdmd bug.d -inline -boundscheck=off Default: TickDuration(58882306) Explicit: TickDuration(49231968) File a bug report, this probably needs Walter to look at it.
Re: Working Windows GUI library - no console Window
On Friday, 6 November 2015 at 15:52:10 UTC, johann wrote: hi, i like to use a window gui library and i think i found a working one. https://github.com/FrankLIKE/dfl2 - works with x64 the problem is, that with DMD 2.069.0, VS2015 and visualD the trick of using "-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup" does not suppress the console window anymore. does anybody have a solution for that problem? is anybody still working on that library? johann Same problem here. I had to remove the mainCRTStartup flag and use WinMain as my entry point.
Re: std.utf.decode behaves unexpectedly - Bug?
Sorry, the forum as stripped my answer. Here is the full version: On Friday, 6 November 2015 at 19:26:50 UTC, HeiHon wrote: Am I using std.utf.decode wrongly or is it buggy? It's obviously used wrongly, try this instead: import std.utf, std.stdio; --- dstring do_decode(string txt) { dstring result; try { size_t idx; writeln("decode ", txt); while (true) { result ~= std.utf.decode(txt, idx); if (idx == txt.length) break; } } catch(Exception e) { writeln(e.msg, " file=", e.file, " line=", e.line); } return result; } void main() { writeln(do_decode("abc")); writeln(do_decode("åbc")); writeln(do_decode("aåb")); } --- Additionally to what's been said in the other answers there was also another error: the `for()` loop was working on code points while there are possibly less code units in `txt`. So instead you can use an infinite loop and break when `txt` is decoded. Alternatively you could also use std.range primitives to decode, which can be considered as a more idiomatic way of doing things, e.g: --- import std.utf, std.stdio, std.range; dstring do_decode(string txt) { dstring result; try { size_t idx; writeln("decode ", txt); while (true) { if (txt.empty) break; result ~= txt.front; txt.popFront; } } catch(Exception e) { writeln(e.msg, " file=", e.file, " line=", e.line); } return result; } void main() { writeln(do_decode("abc")); writeln(do_decode("åbc")); writeln(do_decode("aåb")); } --- because `front` auto decodes it argument. To finish, a hint: you can use the unit tests found in phobos to learn how to use a particular function. Usually there are more than the one put as ddoc.
Re: std.utf.decode behaves unexpectedly - Bug?
On Friday, 6 November 2015 at 19:26:50 UTC, HeiHon wrote: Am I using std.utf.decode wrongly or is it buggy? It's obviously used wrongly, try this instead: import std.utf, std.stdio; --- dstring do_decode(string txt) { dstring result; try { size_t idx; writeln("decode ", txt); while (true) { result ~= std.utf.decode(txt, idx); if (idx == txt.length) break; } } catch(Exception e) { writeln(e.msg, " file=", e.file, " line=", e.line); } return result; } void main() { writeln(do_decode("abc")); writeln(do_decode("åbc")); writeln(do_decode("aåb")); }
Re: std.utf.decode behaves unexpectedly - Bug?
On Friday, 6 November 2015 at 19:26:50 UTC, HeiHon wrote: Consider this: [code] import std.stdio, std.utf, std.exception; void do_decode(string txt) { try { size_t idx; writeln("decode ", txt); for (size_t i = 0; i < txt.length; i++) { dchar dc = std.utf.decode(txt[i..i+1], idx); writeln(" i=", i, " length=", txt[i..i+1].length, " char=", txt[i], " idx=", idx, " dchar=", dc); } } catch(Exception e) { writeln(e.msg, " file=", e.file, " line=", e.line); } writeln(); } void main() { do_decode("abc"); /+ result: decode abc i=0 length=1 char=a idx=1 dchar=a i=1 length=1 char=b idx=2 dchar=c i=2 length=1 char=c idx=3 dchar= +/ do_decode("åbc"); /+ result: decode åbc Attempted to decode past the end of a string (at index 1) file=D:\dmd2\windows\bin\..\..\src\phobos\std\utf.d line=1268 +/ do_decode("aåb"); /+ result: decode aåb i=0 length=1 char=a idx=1 dchar=a core.exception.RangeError@std\utf.d(1265): Range violation 0x004054D4 0x0040214F 0x004045A7 0x004044BB 0x00403008 0x755D339A in BaseThreadInitThunk 0x76EE9EF2 in RtlInitializeExceptionChain 0x76EE9EC5 in RtlInitializeExceptionChain +/ } [/code] I would expect: decode abc -> dchar a, dchar b, dchar c decode åbc -> dchar å, dchar b, dchar c decode aåb -> dchar a, dchar å, dchar b Am I using std.utf.decode wrongly or is it buggy? I wouldn't have thought you would want to do this: dchar dc = std.utf.decode(txt[i..i+1], idx); since txt is utf8, and this is a multiple byte, and variable length encoding, so txt[i..i+1] won't work, you will end up with invalid chops of utf8. It would seem that you might want to just say decode(txt, i) instead if you look at the documentation it should decode one code point and advance i the right amount of characters forward. In other words, perhaps that paired with a while ( i < txt.length) might do the trick.
Re: std.utf.decode behaves unexpectedly - Bug?
Sorry, I mixed up the line numbers from dmd 2.068.2 and dmd 2.069.0. The correct line numbers for dmd 2.069.0 are: Attempted to decode past the end of a string (at index 1) file=D:\dmd2\windows\bin\..\..\src\phobos\std\utf.d line=1281 and core.exception.RangeError@std\utf.d(1278): Range violation
std.utf.decode behaves unexpectedly - Bug?
Consider this: [code] import std.stdio, std.utf, std.exception; void do_decode(string txt) { try { size_t idx; writeln("decode ", txt); for (size_t i = 0; i < txt.length; i++) { dchar dc = std.utf.decode(txt[i..i+1], idx); writeln(" i=", i, " length=", txt[i..i+1].length, " char=", txt[i], " idx=", idx, " dchar=", dc); } } catch(Exception e) { writeln(e.msg, " file=", e.file, " line=", e.line); } writeln(); } void main() { do_decode("abc"); /+ result: decode abc i=0 length=1 char=a idx=1 dchar=a i=1 length=1 char=b idx=2 dchar=c i=2 length=1 char=c idx=3 dchar= +/ do_decode("åbc"); /+ result: decode åbc Attempted to decode past the end of a string (at index 1) file=D:\dmd2\windows\bin\..\..\src\phobos\std\utf.d line=1268 +/ do_decode("aåb"); /+ result: decode aåb i=0 length=1 char=a idx=1 dchar=a core.exception.RangeError@std\utf.d(1265): Range violation 0x004054D4 0x0040214F 0x004045A7 0x004044BB 0x00403008 0x755D339A in BaseThreadInitThunk 0x76EE9EF2 in RtlInitializeExceptionChain 0x76EE9EC5 in RtlInitializeExceptionChain +/ } [/code] I would expect: decode abc -> dchar a, dchar b, dchar c decode åbc -> dchar å, dchar b, dchar c decode aåb -> dchar a, dchar å, dchar b Am I using std.utf.decode wrongly or is it buggy?
Re: Working Windows GUI library - no console Window
On Friday, 6 November 2015 at 15:52:10 UTC, johann wrote: hi, i like to use a window gui library and i think i found a working one. https://github.com/FrankLIKE/dfl2 - works with x64 the problem is, that with DMD 2.069.0, VS2015 and visualD the trick of using "-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup" does not suppress the console window anymore. does anybody have a solution for that problem? is anybody still working on that library? johann Have a look at the resultant executable header with a tool like objdump / pebrowse. In the header somewhere there is a field that specifies the subsystem type. It should be set to gui, rather than console. IMAGE_SUBSYSTEM_WINDOWS_GUI 2 https://msdn.microsoft.com/en-us/library/windows/desktop/ms680339%28v=vs.85%29.aspx
Re: struct constructor co nfusion
On Friday, 6 November 2015 at 17:50:17 UTC, Atila Neves wrote: On Friday, 6 November 2015 at 17:34:29 UTC, Spacen Jasset wrote: Hello, I have read various things about struct constructors, specifically 0 argument constructors, and using opCall and @disable this(); which no longer seems to work. What I am after I think is the behavior of C++'s structs on the stack, namely for some or all of these uses at a given time: 1. Allocation on the stack 2. Value type semantics 3. RAII (combined with (1) often) This is common in D as well. The difference to C++ is 0-argument struct constructors to do extra work to satisfy invariants. Is it the case that a struct should now be used with a factory method? Does this also mean that the struct destructor must be It's the easiest way to emulate C++'s 0-argument struct constructors. made to work when .init is called instead of the factory method? If the factory method isn't called, then yes, the destructor shouldn't blow up just because all the struct members are T.init. This idiom is inconsistent with struct constructors that do have one or more arguments, and I think that this question is likely to arise time immemorial from others who are not expecting this particular inconstancy. How is it inconsistent? Nobody stops me from doing this: struct Struct { void* ptr = cast(void*)5; this(int size) { ptr = malloc(size); } ~this() { free(ptr); } } void main() { auto ok = Struct(10); //auto oops = Struct.init; } Atila What I mean is that: this(int a, int b) {} is allowed Whereas: this() {} isn't allowed. I see why that is the case now, but it seems inconsistent to me, and I think each new person that comes to D is going to wonder about this. Also, I had to add a dummy private constructor to make my structs 'createable', or is there another way? e.g. struct Texture { @disable this(); static Texture create() { return Texture(0); } ... private: this(int) { glGenTextures(1, &textureId_); enforce(0 != textureId_); } GLuint textureId_; }
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 13:16:46 UTC, Suliman wrote: I wrote Application in D. That use next components: "colorize": ">=1.0.5", "ddbc": ">=0.2.11", "vibe-d": "~>0.7.26" On Windows 7 it's work fine. On Windows 10 (clean install) it's do not start and require MSVCR120.dll And I can't understand what component is pulling this lib as dependence. What would be if I am try to port my App to Linux? What compiler are you using?
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 13:16:46 UTC, Suliman wrote: On Windows 7 it's work fine. On Windows 10 (clean install) it's do not start and require MSVCR120.dll D doesn't make particularly heavy use of the C runtime, so there's a good chance you can link against a different C runtime DLL — preferably one that's always available by default like msvcrt.dll. However I'd start by determining why it works fine on 7 and not on 10. It could be that MSVCR120.dll is in your library search path on your Win7 system for some reason, or perhaps the compiler is somehow choosing to link against a different runtime when compiling on Windows 7. If you don't already have tools to inspect this stuff, PeStudio ( https://www.winitor.com/ ) will be helpful — it can tell you all the load-time dynamic linkage for a given executable (among other things).
Re: Align a variable on the stack.
I did some testing on Linux and Windows. I ran the code with ten times the iterations, and found the results consistent with what has previously been observed in this thread. The code seems to run just fine on Linux, but is slowed down 10x on Windows x86. Windows (32-bit) rdmd bug.d -inline -boundscheck=off -release Default: TickDuration(14398890) Explicit: TickDuration(16) Linux (64-bit) rdmd bug.d -m64 -inline -boundscheck=off Default: TickDuration(59090876) Explicit: TickDuration(49529493) Linux (32-bit) rdmd bug.d -inline -boundscheck=off Default: TickDuration(58882306) Explicit: TickDuration(49231968)
Re: struct constructor co nfusion
On Friday, 6 November 2015 at 17:34:29 UTC, Spacen Jasset wrote: Hello, I have read various things about struct constructors, specifically 0 argument constructors, and using opCall and @disable this(); which no longer seems to work. What I am after I think is the behavior of C++'s structs on the stack, namely for some or all of these uses at a given time: 1. Allocation on the stack 2. Value type semantics 3. RAII (combined with (1) often) This is common in D as well. The difference to C++ is 0-argument struct constructors to do extra work to satisfy invariants. Is it the case that a struct should now be used with a factory method? Does this also mean that the struct destructor must be It's the easiest way to emulate C++'s 0-argument struct constructors. made to work when .init is called instead of the factory method? If the factory method isn't called, then yes, the destructor shouldn't blow up just because all the struct members are T.init. This idiom is inconsistent with struct constructors that do have one or more arguments, and I think that this question is likely to arise time immemorial from others who are not expecting this particular inconstancy. How is it inconsistent? Nobody stops me from doing this: struct Struct { void* ptr = cast(void*)5; this(int size) { ptr = malloc(size); } ~this() { free(ptr); } } void main() { auto ok = Struct(10); //auto oops = Struct.init; } Atila
struct constructor co nfusion
Hello, I have read various things about struct constructors, specifically 0 argument constructors, and using opCall and @disable this(); which no longer seems to work. What I am after I think is the behavior of C++'s structs on the stack, namely for some or all of these uses at a given time: 1. Allocation on the stack 2. Value type semantics 3. RAII (combined with (1) often) The scope keyword on classes has been deprecated, it seems because it was hard to detect returning destroyed scope references, otherwise that might have done the job. Is it the case that a struct should now be used with a factory method? Does this also mean that the struct destructor must be made to work when .init is called instead of the factory method? This idiom is inconsistent with struct constructors that do have one or more arguments, and I think that this question is likely to arise time immemorial from others who are not expecting this particular inconstancy. Would it not make sense to ban constructors on structs entirely -- or find another solution that clears this up?
Re: Align a variable on the stack.
On Friday, 6 November 2015 at 11:38:29 UTC, Marc Schütz wrote: On Friday, 6 November 2015 at 11:37:22 UTC, Marc Schütz wrote: Ok, benchA and benchB have the same assembler code generated. However, I _can_ reproduce the slowdown albeit on average only 20%-40%, not a factor of 10. Forgot to add that this is on Linux x86_64, so that probably explains the difference. It turns out that it's always the first tested function that's slower. You can test this by switching benchA and benchB in the call to benchmark(). I suspect the reason is that the OS is paging in the code the first time, and we're actually seeing the cost of the page fault. If you a second round of benchmarks after the first one, that one shows more or less the same performance for both functions. I tested swapping around the functions on windows x86 and I still get the same slowdown with the default initializer. Still basically the same running speed of both functions on windows x64. Interestingly enough the slowdown disappear if I add another float variable to the structs. This causes the assembly to change to using different instructions so I guess that is why. Also it only seems to affect small structs with floats in them. If I change the memebers to int both versions run at the same speed on x86 aswell.
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 16:21:35 UTC, Suliman wrote: On Friday, 6 November 2015 at 13:50:56 UTC, Kagamin wrote: MSVCR is a C runtime. On Linux it will depend on a C runtime too. But which part of my App depend on C runtime? I have an early draft to explain the libraries here: https://bitbucket.org/timosi/minlibd/wiki/libc_vs_libgcc It is the Linux point of view but the basics are the same. It would be hard to write generic patterns that describe all possible language features for all possible target systems. It is easier to put them into a separate library that is common for all apps. Some simple things are math with mixed types and fp math, more complex things are for example thread and exception handling.
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 16:21:35 UTC, Suliman wrote: On Friday, 6 November 2015 at 13:50:56 UTC, Kagamin wrote: MSVCR is a C runtime. On Linux it will depend on a C runtime too. But which part of my App depend on C runtime? All of it. Phobos and druntime use the C runtime, that means the language itself depends on the C runtime.
Re: Why my app require MSVCR120.dll?
On Friday, 6 November 2015 at 13:50:56 UTC, Kagamin wrote: MSVCR is a C runtime. On Linux it will depend on a C runtime too. But which part of my App depend on C runtime?
Working Windows GUI library - no console Window
hi, i like to use a window gui library and i think i found a working one. https://github.com/FrankLIKE/dfl2 - works with x64 the problem is, that with DMD 2.069.0, VS2015 and visualD the trick of using "-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup" does not suppress the console window anymore. does anybody have a solution for that problem? is anybody still working on that library? johann
Re: Associative array with duplicated keys?
On Friday, 6 November 2015 at 14:28:53 UTC, cym13 wrote: auto aa = ["a":10, "b", 42, "a":20]; This should readauto aa = ["a":10, "b":42, "a":20]; of course.
Re: Associative array with duplicated keys?
On Thursday, 5 November 2015 at 13:08:20 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana wrote: Anyway: are duplicated keys on declaration allowed? They shouldn't be... Why? I'll admit it is something I've never even thought of using, but every language I know (just tested with python, lua, scheme and js) accepts it and as far as I can tell from a user perspective boils auto aa = ["a":10, "b", 42, "a":20]; down to: int[string] aa; aa["a"] = 10; aa["b"] = 42; aa["a"] = 20; This is deterministic and could allow one to build an associative array through a mixin for example while still giving default values. As I said, it's not something I've used but I think we should consider it.
Re: Why my app require MSVCR120.dll?
MSVCR is a C runtime. On Linux it will depend on a C runtime too.
Why my app require MSVCR120.dll?
I wrote Application in D. That use next components: "colorize": ">=1.0.5", "ddbc": ">=0.2.11", "vibe-d": "~>0.7.26" On Windows 7 it's work fine. On Windows 10 (clean install) it's do not start and require MSVCR120.dll And I can't understand what component is pulling this lib as dependence. What would be if I am try to port my App to Linux?
Re: conver BigInt to string
On Friday, 6 November 2015 at 10:00:23 UTC, Namal wrote: On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Bye, bearophile can I import libraries anywhere? Is this the proper way to do so? You can, and some say you should. The thing is, if you use templates and import the necessary libraries within the template then the import occurs only if the template is instantiated which can be a big gain. Phobos makes great use of this technique for example.
Re: Align a variable on the stack.
Ok, benchA and benchB have the same assembler code generated. However, I _can_ reproduce the slowdown albeit on average only 20%-40%, not a factor of 10. It turns out that it's always the first tested function that's slower. You can test this by switching benchA and benchB in the call to benchmark(). I suspect the reason is that the OS is paging in the code the first time, and we're actually seeing the cost of the page fault. If you a second round of benchmarks after the first one, that one shows more or less the same performance for both functions.
Re: Align a variable on the stack.
On Friday, 6 November 2015 at 11:37:22 UTC, Marc Schütz wrote: Ok, benchA and benchB have the same assembler code generated. However, I _can_ reproduce the slowdown albeit on average only 20%-40%, not a factor of 10. Forgot to add that this is on Linux x86_64, so that probably explains the difference. It turns out that it's always the first tested function that's slower. You can test this by switching benchA and benchB in the call to benchmark(). I suspect the reason is that the OS is paging in the code the first time, and we're actually seeing the cost of the page fault. If you a second round of benchmarks after the first one, that one shows more or less the same performance for both functions.
Re: Unittest in a library
On Friday, 6 November 2015 at 04:34:28 UTC, TheFlyingFiddle wrote: On Friday, 6 November 2015 at 03:59:07 UTC, Charles wrote: Is it possible to have unittest blocks if I'm compiling a library? I've tried having this: test.d: class Classy { unittest { assert(0, "failed test"); } } and then build it with `dmd test.d -lib -unittest` and it doesn't fail the unittest. You can test the unittests by using the -main switch. http://dlang.org/dmd-linux.html#switch-main That's exactly what I was missing. Thanks!
Re: conver BigInt to string
On Thursday, 5 November 2015 at 17:40:12 UTC, bearophile wrote: Namal: Hello I am trying to convert BigInt to string like that while trying to sort it: void main() { import std.stdio, std.algorithm, std.conv, std.bigint, std.string; auto n = 17.BigInt ^^ 179; n.text.dup.representation.sort().release.assumeUTF.writeln; } Bye, bearophile can I import libraries anywhere? Is this the proper way to do so?
Re: Maybe a dmd bug, what do you think ?
On Friday, 6 November 2015 at 08:48:38 UTC, user123456789abcABC wrote: Template parameter deduction in partially specialized template fails: --- enum Bar{b,a,r} void foo(Bar bar, T)(T t){} alias foob(T) = foo!(Bar.b, T); void main() { foo!(Bar.b)(8); foob(8); // autsch } --- It looks like a bug, doesn't it ? I believe this is https://issues.dlang.org/show_bug.cgi?id=1807
Maybe a dmd bug, what do you think ?
Template parameter deduction in partially specialized template fails: --- enum Bar{b,a,r} void foo(Bar bar, T)(T t){} alias foob(T) = foo!(Bar.b, T); void main() { foo!(Bar.b)(8); foob(8); // autsch } --- It looks like a bug, doesn't it ?