Re: union.sizeof
On Sunday, 26 March 2017 at 06:45:13 UTC, ketmar wrote: yes. you have a typo in second `writefln`: S1 instead of S2. ;-) thank you. another question, related to my first post: why size of S2.b1 and S2.b2 still 3, not 4? am i right: then align applied to members, compiler not change size of members, just make padding, so CONTAINER size changes? if so (because size of S2.b1 and S2.b2 still is 3 in my code), then adding align(1) outside of union must not change zise of union, but size of some comainer more upper level.
foreach, is and pointer
What's the difference between 1. string x = "abcd"; foreach(character; x) write(character); and string x = "abcd"; foreach(character; x[0..$]) write(character); 2. is and == 3. pointer and address and reference?
Re: union.sizeof
On Sunday, 26 March 2017 at 06:38:59 UTC, zabruk70 wrote: oh sorry sorry - mistyping ok. DMD use padding, so for real container.sizeof i should use lastMemeber.offsetof+lastMemeber.sizeof
Re: union.sizeof
zabruk70 wrote: On Sunday, 26 March 2017 at 05:09:15 UTC, ketmar wrote: most of the time either location or padding will work the same. hmm.. you ruined my expirence.. i made another experiment. whould you please explain me S2 size 6? thank you for you time. yes. you have a typo in second `writefln`: S1 instead of S2. ;-)
Re: union.sizeof
On Sunday, 26 March 2017 at 05:09:15 UTC, ketmar wrote: most of the time either location or padding will work the same. hmm.. you ruined my expirence.. i made another experiment. whould you please explain me S2 size 6? thank you for you time. https://dpaste.dzfl.pl/9a31b6e370a0 struct S1 //sizeof=6 { align(1): byte[3] b1; //offsetof=0, sizeof=3 byte[3] b2; //offsetof=3, sizeof=3 } struct S2 //sizeof must be 7, but DMD say 6 { align(4): byte[3] b1; //offsetof=0, sizeof=3 byte[3] b2; //offsetof=4, sizeof=3 }
Re: Recommend: IDE and GUI library
On Wednesday, 1 March 2017 at 20:23:57 UTC, aberba wrote: On Friday, 24 February 2017 at 22:44:55 UTC, XavierAP wrote: [...] Gtkd is obviously defacto for Linux ONLY, dlangui for cross platform app without native feel. But if you want something easy and flexible with native look and feel on all platforms, well tested, use LibUI (http://code.dlang.org/packages/libuid). Look inside the "examples" folder in their Github repository to see example usage. More like: auto hbox = new Box(false).setPadded(1); vbox.append(hbox); hbox.append(new Button("Button")) .append(new Checkbox("Checkbox")) ... Examples: https://github.com/mogud/libuid/blob/master/examples/example1.d https://github.com/mogud/libuid/blob/master/examples/example2.d I second this. I've been playing with this recently and it's really easy to use.
Re: union.sizeof
zabruk70 wrote: Thank you ag0aep6g and ketmar!! I will use additional outside align. I want packing inside, you are right. But i check result size with assert() and failed. But for clearness... I was thinked, that align not changes SIZE, but changes LOCATION. I was thinked, that "align(X) union Union1" just force compiler to place Union1 on boundaries of X bytes... most of the time either location or padding will work the same. ;-) but no, the idea of aligning is that structs/unions/etc. that comes together one after another are aligned from the starting offset of the first element, not from "address zero" for the whole app.
Re: Howto catch SocketOSException?
On Sunday, 26 March 2017 at 02:24:56 UTC, Jolly James wrote: You can ignore the loop()-method. It is not called as the application will never reach this statement, because it cannot, because it crashes already in the listen()-method in consequence of the exception that does not get caught by the try-catch block. Try putting it in the try anyway and see what happens. It is an async socket library, they can do weird things.\
Re: Howto catch SocketOSException?
On Sunday, 26 March 2017 at 01:22:24 UTC, bauss wrote: On Sunday, 26 March 2017 at 00:34:03 UTC, Jolly James wrote: [...] This part: catch (std.socket.SocketOSException e) [...] [...] I know that inheritance stuff, but none (!) of them catches that strange exception either. You can ignore the loop()-method. It is not called as the application will never reach this statement, because it cannot, because it crashes already in the listen()-method in consequence of the exception that does not get caught by the try-catch block. std.socket.SocketOSException@std\socket.d(975): getaddrinfo error: Unknow host. 0x004205BE in pure @safe bool std.exception.enforce!(bool).enforce(bool, lazy object.Throwable) 0x0040D3A2 in @trusted std.socket.AddressInfo[] std.socket.getAddressInfo!(immutable(char)[], std.socket.AddressInfoFlags, std.socket.SocketType, std.socket.ProtocolType).getAddressInfo(const(char[]), immutable(char)[], std.socket.AddressInfoFlags, std.socket.SocketType, std.socket.ProtocolType).__lambda7() 0x0040D37B in @safe std.socket.AddressInfo[] std.socket.getAddressInfo!(immutable(char)[], std.socket.AddressInfoFlags, std.socket.SocketType, std.socket.ProtocolType).getAddressInfo(const(char[]), immutable(char)[], std.socket.AddressInfoFlags, std.socket.SocketType, std.socket.ProtocolType) at C:\dlang\dmd2\windows\bin\..\..\src\phobos\std\socket.d(945) 0x00404DAF in ushort ae.net.asockets.TcpServer.listen(ushort, immutable(char)[]) at C:\Users\jolly\src\ae\net\asockets.d(1242) 0x00416749 in _Dmain at C:\Users\jolly\src\app.d(48) 0x00423597 in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 0x0042355B in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x0042345C in _d_run_main 0x00417D74 in main at C:\Users\jolly\src\ae\net\asockets.d(7) 0x00443EBD in mainCRTStartup 0x757362C4 in BaseThreadInitThunk 0x773C0FD9 in RtlSubscribeWnfStateChangeNotification 0x773C0FA4 in RtlSubscribeWnfStateChangeNotification ↑ stacktrace
Re: Howto catch SocketOSException?
On Sunday, 26 March 2017 at 00:34:03 UTC, Jolly James wrote: How do you catch an std.socket.SocketOSException? The following does not work, as the exception occurs anyway and leads to a crash: import ae.net.asockets; void main(string[] args) { TcpServer tcp = new TcpServer(); try { tcp.listen(2345, "127.0.0.1c"); // '...c' makes the IP address invalid } catch (std.socket.SocketOSException e) { return; } catch (Exception e) { return; } socketManager.loop(); } Output: std.socket.SocketOSException@std\socket.d(975): getaddrinfo error: Unknown Host This part: catch (std.socket.SocketOSException e) { return; } Is redundant, because SocketOSException inherits SocketException which inherits Exception. It should already be caught by catch (Exception e) You should have a full stacktrace, chances are that it's invoked in your loop()?
Re: union.sizeof
On Saturday, 25 March 2017 at 23:36:07 UTC, kinke wrote: On Saturday, 25 March 2017 at 22:45:22 UTC, ketmar wrote: zabruk70 wrote: [...] `align(1) union Union1` will do the trick. what you did is members packing. but the union itself is padded to integer size too. i.e. internal `align` will set aligning for *members*, and external `align` will change padding of the whole thing. The union should have an implicit alignment of 1 already though, right? It's defined as the maximum of all member alignments, and both the bytes5 array and the anonymous struct members have an explicit alignment of 1. The alignment of the anonymous struct's int1 member (explicitly 1 too) shouldn't even matter. Why should it have an implicit alignment of 1? The alignment completely depends on the definition unless specified AFAIK.
Howto catch SocketOSException?
How do you catch an std.socket.SocketOSException? The following does not work, as the exception occurs anyway and leads to a crash: import ae.net.asockets; void main(string[] args) { TcpServer tcp = new TcpServer(); try { tcp.listen(2345, "127.0.0.1c"); // '...c' makes the IP address invalid } catch (std.socket.SocketOSException e) { return; } catch (Exception e) { return; } socketManager.loop(); } Output: std.socket.SocketOSException@std\socket.d(975): getaddrinfo error: Unknown Host
Re: union.sizeof
On Saturday, 25 March 2017 at 22:45:22 UTC, ketmar wrote: zabruk70 wrote: //DMD 2.073.1 and latest 2.075.0-master-972eaed //Windows 7 32-bit union Union1 { align(1): byte[5] bytes5; struct { align(1): char char1; uint int1; } } void main () { import std.stdio: writefln; writefln("Union1.sizeof=%d", Union1.sizeof); //prints 8, not 5 } I expect size of Union1 is 5 (5 bytes == char + uint == 5). Is this my bug or DMD? `align(1) union Union1` will do the trick. what you did is members packing. but the union itself is padded to integer size too. i.e. internal `align` will set aligning for *members*, and external `align` will change padding of the whole thing. The union should have an implicit alignment of 1 already though, right? It's defined as the maximum of all member alignments, and both the bytes5 array and the anonymous struct members have an explicit alignment of 1. The alignment of the anonymous struct's int1 member (explicitly 1 too) shouldn't even matter.
Re: union.sizeof
On Saturday, 25 March 2017 at 22:54:30 UTC, zabruk70 wrote: But for clearness... I was thinked, that align not changes SIZE, but changes LOCATION. I was thinked, that "align(X) union Union1" just force compiler to place Union1 on boundaries of X bytes... In order for all Union1 instances in an array to be aligned on boundaries of X bytes, the size of Union1 needs to be padded to a multiple of X in such a case.
Re: union.sizeof
Thank you ag0aep6g and ketmar!! I will use additional outside align. I want packing inside, you are right. But i check result size with assert() and failed. But for clearness... I was thinked, that align not changes SIZE, but changes LOCATION. I was thinked, that "align(X) union Union1" just force compiler to place Union1 on boundaries of X bytes...
Re: union.sizeof
zabruk70 wrote: //DMD 2.073.1 and latest 2.075.0-master-972eaed //Windows 7 32-bit union Union1 { align(1): byte[5] bytes5; struct { align(1): char char1; uint int1; } } void main () { import std.stdio: writefln; writefln("Union1.sizeof=%d", Union1.sizeof); //prints 8, not 5 } I expect size of Union1 is 5 (5 bytes == char + uint == 5). Is this my bug or DMD? `align(1) union Union1` will do the trick. what you did is members packing. but the union itself is padded to integer size too. i.e. internal `align` will set aligning for *members*, and external `align` will change padding of the whole thing.
Re: union.sizeof
On 03/25/2017 11:37 PM, zabruk70 wrote: union Union1 { align(1): byte[5] bytes5; struct { align(1): char char1; uint int1; } } void main () { import std.stdio: writefln; writefln("Union1.sizeof=%d", Union1.sizeof); //prints 8, not 5 } I'm not sure how the align stuff is supposed to work exactly, but you get 5 when you add `align(1)` to the union itself, too: align(1) union Union1 { align(1): byte[5] bytes5; struct { char char1; uint int1; } } pragma(msg, Union1.sizeof); /* "5LU" */
union.sizeof
//DMD 2.073.1 and latest 2.075.0-master-972eaed //Windows 7 32-bit union Union1 { align(1): byte[5] bytes5; struct { align(1): char char1; uint int1; } } void main () { import std.stdio: writefln; writefln("Union1.sizeof=%d", Union1.sizeof); //prints 8, not 5 } I expect size of Union1 is 5 (5 bytes == char + uint == 5). Is this my bug or DMD? Can anybody reproduce?
Re: 'fopen64 cannot be interpreted at compile time' for __gshared File
On Saturday, 25 March 2017 at 16:46:00 UTC, crimaniak wrote: On Saturday, 25 March 2017 at 16:08:49 UTC, NotSpooky wrote: __gshared implies static,... Thanks! Confusing for me moment. try this: import std.stdio; void main() { import std.stdio; __gshared File f; f = File("test.txt", "w"); f.writeln("hello"); }
Re: recommend Git GUI client for Linux?
On Thursday, 2 March 2017 at 06:16:09 UTC, Patrick Schluter wrote: Here [1] is the official git page listing all GUI clients for different plartforms. I use GitExtensions[2] and I like it a lot. It works very well and all the complicated stuff can be done from the GUI interface and also from command line. Patrick thanks for the great recommendation! I'm using GitExtensions now on Windows. In comparison I wonder how GitHub's desktop client is even allowed on the Internet. For Linux (Lubuntu) any recommendation among these? https://git-scm.com/download/gui/linux
Re: 'fopen64 cannot be interpreted at compile time' for __gshared File
On Saturday, 25 March 2017 at 16:08:49 UTC, NotSpooky wrote: __gshared implies static,... Thanks! Confusing for me moment.
Re: 'fopen64 cannot be interpreted at compile time' for __gshared File
On Saturday, 25 March 2017 at 15:52:15 UTC, crimaniak wrote: Simple File test: void main() { import std.stdio; File f = File("test.txt", "w"); f.writeln("hello"); } All works as expected. Now let's add __gshared: void main() { import std.stdio; __gshared File f = File("test.txt", "w"); f.writeln("hello"); } Now we have: /usr/include/dmd/phobos/std/stdio.d(3797): Error: fopen64 cannot be interpreted at compile time, because it has no available source code /usr/include/dmd/phobos/std/stdio.d(3804):called from here: fopenImpl(namez.ptr(), modez.ptr()) /usr/include/dmd/phobos/std/stdio.d(404):called from here: fopen(name, stdioOpenmode) /usr/include/dmd/phobos/std/stdio.d(404):called from here: errnoEnforce(fopen(name, stdioOpenmode), delegate string() => text("Cannot open file `", name, "' in mode `", stdioOpenmode, "'")) /usr/include/dmd/phobos/std/stdio.d(404):called from here: this.this(errnoEnforce(fopen(name, stdioOpenmode), delegate string() => text("Cannot open file `", name, "' in mode `", stdioOpenmode, "'")), name, 1u, false) file.d(5):called from here: ((File __slFile648 = File(null, null);) , __slFile648).this("test.txt", "w") Oooops! Who can explain this error message to me? DMD64 D Compiler v2.073.0 __gshared implies static, that is, known at compile time (ct), that means the File constructor should be done at ct and thus open the file. Compile time function execution doesn't allow IO operations, however you can use https://dlang.org/spec/expression.html#ImportExpression if you want to read a file at compile time.
'fopen64 cannot be interpreted at compile time' for __gshared File
Simple File test: void main() { import std.stdio; File f = File("test.txt", "w"); f.writeln("hello"); } All works as expected. Now let's add __gshared: void main() { import std.stdio; __gshared File f = File("test.txt", "w"); f.writeln("hello"); } Now we have: /usr/include/dmd/phobos/std/stdio.d(3797): Error: fopen64 cannot be interpreted at compile time, because it has no available source code /usr/include/dmd/phobos/std/stdio.d(3804):called from here: fopenImpl(namez.ptr(), modez.ptr()) /usr/include/dmd/phobos/std/stdio.d(404):called from here: fopen(name, stdioOpenmode) /usr/include/dmd/phobos/std/stdio.d(404):called from here: errnoEnforce(fopen(name, stdioOpenmode), delegate string() => text("Cannot open file `", name, "' in mode `", stdioOpenmode, "'")) /usr/include/dmd/phobos/std/stdio.d(404):called from here: this.this(errnoEnforce(fopen(name, stdioOpenmode), delegate string() => text("Cannot open file `", name, "' in mode `", stdioOpenmode, "'")), name, 1u, false) file.d(5):called from here: ((File __slFile648 = File(null, null);) , __slFile648).this("test.txt", "w") Oooops! Who can explain this error message to me? DMD64 D Compiler v2.073.0
Re: Exporting template function instances to C
On Saturday, 25 March 2017 at 06:17:15 UTC, Nicholas Wilson wrote: On Saturday, 25 March 2017 at 02:21:33 UTC, data pulverizer wrote: Thanks a lot ... I was half joking playing with the name "mangling" but I appreciate your explanations and suggestions. This is the internet, I can't tell if you're a newb or sarcastic, and given this is a learn forum I'm going to make a conservative estimate of the former ;) (possibly 'cause I was half asleep when answering) I would however be interested to know if the extern(C++)/__attribute__((overloadable))/Instansiate combo actually worked. I usually try to be as clear as possible, I just couldn't help slipping in a joke with a name like "mangling" I could not resits. I am definitely a noob to compilers, my day job is a data scientist/statistician, however I really like the D programming language and I am increasing my knowledge by blogging, writing D interfaces for C libraries and I am building a low performance BLAS alternative to GLAS (https://github.com/dataPulverizer/dblas) - its funny because its true! The article I am working on is connecting D to other languages. The draft for my article interfacing D to C and Fortran is here (https://github.com/dataPulverizer/interface-d-c-fortran). I can't decide if name mangling deserves its own topic. Feel free to put in a suggestion/pull request to either.