Re: __traits(compiles,...) <=> ? is(typeof(...))

2012-10-30 Thread Don Clugston
On 29/10/12 12:03, Jonathan M Davis wrote: On Monday, October 29, 2012 11:42:59 Zhenya wrote: Hi! Tell me please,in this code first and second static if,are these equivalent? with arg = 1, __traits(compiles,"check(arg);") = true, is(typeof(check(arg))) = false. In principle, is(typeof(code))

Interesting C header translation problem

2012-10-30 Thread Nick Sabalausky
Came across this: #ifdef __GNUC__ #define PACKED __attribute__((packed)) #else #define PACKED #endif typedef enum { // Lots o' stuff } PACKED my_enum_t; typedef struct { // Lots o' stuff const void *ptr; } PACKED my_struct_t; T

Re: How to place char* of stringZ to ubyte[]?

2012-10-30 Thread Nick Sabalausky
On Mon, 29 Oct 2012 19:50:57 +0100 "bearophile" wrote: > denizzzka: > > > I am trying to send to remote host utf8 text with zero byte at > > end (required by protocol) > > What if your UTF8 string coming from D already contains several > zeros? > If you need to send a string with an embedde

Re: Interesting C header translation problem

2012-10-30 Thread Alex Rønne Petersen
On 30-10-2012 10:41, Nick Sabalausky wrote: Came across this: #ifdef __GNUC__ #define PACKED __attribute__((packed)) #else #define PACKED #endif typedef enum { // Lots o' stuff } PACKED my_enum_t; typedef struct { // Lots o' stu

Callbacks and interfacing with C

2012-10-30 Thread Nick Sabalausky
Ok, a C function pointer like this: struct MyStruct{ int (*foo)(int); }; Translates to D as this: struct MyStruct{ int function(int) foo; } But what about calling conventions? There isn't any "int extern(C) function(int)" is there? Not sure if that would even mak

Re: Callbacks and interfacing with C

2012-10-30 Thread Alex Rønne Petersen
On 30-10-2012 11:13, Nick Sabalausky wrote: Ok, a C function pointer like this: struct MyStruct{ int (*foo)(int); }; Translates to D as this: struct MyStruct{ int function(int) foo; } But what about calling conventions? There isn't any "int extern(C) func

Re: Interesting C header translation problem

2012-10-30 Thread Nick Sabalausky
On Tue, 30 Oct 2012 11:05:28 +0100 Alex Rønne Petersen wrote: > On 30-10-2012 10:41, Nick Sabalausky wrote: > > Came across this: > > > > #ifdef __GNUC__ > > #define PACKED __attribute__((packed)) > > #else > > #define PACKED > > #endif > > > > typedef enum {

Re: Callbacks and interfacing with C

2012-10-30 Thread Nick Sabalausky
On Tue, 30 Oct 2012 11:15:55 +0100 Alex Rønne Petersen wrote: > On 30-10-2012 11:13, Nick Sabalausky wrote: > > Ok, a C function pointer like this: > > > > struct MyStruct{ > > int (*foo)(int); > > }; > > > > Translates to D as this: > > > > struct MyStruct{ > > i

Re: Copying with immutable arrays

2012-10-30 Thread Don Clugston
On 29/10/12 07:19, Ali Çehreli wrote: On 10/28/2012 02:37 AM, Tobias Pankrath wrote: > the struct > SwA from above does neither correspond to SA nor to SB, it's imo more > like SC: > > struct SC { > immutable(int)* i; > } Just to confirm, the above indeed works: struct SC { immutabl

Re: Callbacks and interfacing with C

2012-10-30 Thread bearophile
Nick Sabalausky: Which, if any, of foo1/foo2/foo3 are extern(C)? (I know bar definitely is.) A general comment: if you are not sure of the answer, then the programmer that will read your code will probably have similar problems. So in such cases it's better to try to not write that code.

Re: How to place char* of stringZ to ubyte[]?

2012-10-30 Thread bearophile
denizzzka: I am concerned about the extra allocations of temp arrays. here is it, or not? compiler optimizes it? There is one allocation, and usually the D compilers can't optimize it away. In my case it does not matter but for the future I would like to know how it can be implemented wit

DFL Button.backColor

2012-10-30 Thread Zhenya
Hi! Explain me please,why this code doesn't work import dfl.all; void main() { auto form = new Form; auto button = new Button; button.backColor = Color(0,0,0); button.foreColor = Color(0,0,0); form.controls.add(button); Application.run(form); } I

finding composed structs

2012-10-30 Thread Dan
Please help me with any flaws in logic or understanding: For any struct S, '==' means either bitwise comparison or a call to opEquals of S if it exists. If S has no (dynamic arrays, associative arrays, pointers, or class references as members (recursively)) then bitwise compare is equivalent t

Re: DFL Button.backColor

2012-10-30 Thread Zhenya
On Tuesday, 30 October 2012 at 13:34:21 UTC, Zhenya wrote: Hi! Explain me please,why this code doesn't work import dfl.all; void main() { auto form = new Form; auto button = new Button; button.backColor = Color(0,0,0); button.foreColor = Color(0,0,0); fo

Re: finding composed structs

2012-10-30 Thread Tobias Pankrath
On Tuesday, 30 October 2012 at 15:26:22 UTC, Dan wrote: Please help me with any flaws in logic or understanding: For any struct S, '==' means either bitwise comparison or a call to opEquals of S if it exists. If S has no (dynamic arrays, associative arrays, pointers, or class references as mem

Re: UTF-8 strings and endianness

2012-10-30 Thread Jesse Phillips
On Monday, 29 October 2012 at 15:22:39 UTC, Adam D. Ruppe wrote: UTF-8 isn't affected by endianness. If this is true why does the BOM have marks for big and little endian? http://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding

Re: UTF-8 strings and endianness

2012-10-30 Thread Tobias Pankrath
On Tuesday, 30 October 2012 at 17:12:41 UTC, Jesse Phillips wrote: On Monday, 29 October 2012 at 15:22:39 UTC, Adam D. Ruppe wrote: UTF-8 isn't affected by endianness. If this is true why does the BOM have marks for big and little endian? http://en.wikipedia.org/wiki/Byte_order_mark#Represe

Re: Callbacks and interfacing with C

2012-10-30 Thread Andrej Mitrovic
On 10/30/12, Nick Sabalausky wrote: > Which, if any, of foo1/foo2/foo3 are extern(C)? (I know bar definitely > is.) All of them. void main() { pragma(msg, MyFn); pragma(msg, typeof(MyStruct.foo2)); pragma(msg, typeof(bar)); } extern (C) int function(int) extern (C) int function(int)

Re: Threading Question

2012-10-30 Thread Sean Kelly
On Oct 25, 2012, at 11:18 PM, Jacob Carlborg wrote: > On 2012-10-26 01:18, Sean Kelly wrote: >> On Oct 25, 2012, at 4:12 PM, Alex Rønne Petersen wrote: >>> >>> What's used on OS X? I forget... >> >> The method used is similar to how GC works on Windows--there's a kernel call >> that can be us

Re: UTF-8 strings and endianness

2012-10-30 Thread Dmitry Olshansky
10/30/2012 5:17 PM, Tobias Pankrath пишет: On Tuesday, 30 October 2012 at 17:12:41 UTC, Jesse Phillips wrote: On Monday, 29 October 2012 at 15:22:39 UTC, Adam D. Ruppe wrote: UTF-8 isn't affected by endianness. If this is true why does the BOM have marks for big and little endian? http://en.

Re: Threading Question

2012-10-30 Thread Alex Rønne Petersen
On 30-10-2012 19:04, Sean Kelly wrote: On Oct 25, 2012, at 11:18 PM, Jacob Carlborg wrote: On 2012-10-26 01:18, Sean Kelly wrote: On Oct 25, 2012, at 4:12 PM, Alex Rønne Petersen wrote: What's used on OS X? I forget... The method used is similar to how GC works on Windows--there's a kern

Re: finding composed structs

2012-10-30 Thread Dan
On Tuesday, 30 October 2012 at 16:44:02 UTC, Ali Çehreli wrote: There is the following discussion currently on the main D forum: http://forum.dlang.org/thread/iphhuttpkogmfwpuv...@forum.dlang.org That behavior will be changed: http://forum.dlang.org/thread/iphhuttpkogmfwpuv...@forum.dlang.

Re: crash suggestions

2012-10-30 Thread Dan
On Monday, 29 October 2012 at 23:02:46 UTC, Ali Çehreli wrote: I wonder whether this bug is related to your case: http://d.puremagic.com/issues/show_bug.cgi?id=5570 After all, you do pass a struct that includes non-integral types. That bug may be it. Ali Thanks for following up and all

Re: Callbacks and interfacing with C

2012-10-30 Thread Jacob Carlborg
On 2012-10-30 18:44, Andrej Mitrovic wrote: All of them. void main() { pragma(msg, MyFn); pragma(msg, typeof(MyStruct.foo2)); pragma(msg, typeof(bar)); } extern (C) int function(int) extern (C) int function(int) extern (C) void(extern (C) int function(int) foo3) extern (C) int f

Re: UTF-8 strings and endianness

2012-10-30 Thread Jesse Phillips
On Tuesday, 30 October 2012 at 17:17:36 UTC, Tobias Pankrath wrote: On Tuesday, 30 October 2012 at 17:12:41 UTC, Jesse Phillips wrote: On Monday, 29 October 2012 at 15:22:39 UTC, Adam D. Ruppe wrote: UTF-8 isn't affected by endianness. If this is true why does the BOM have marks for big and l

Re: finding composed structs

2012-10-30 Thread Tobias Pankrath
On Tuesday, 30 October 2012 at 20:16:12 UTC, Tobias Pankrath wrote: In the meantime you can use this function template to compare structs field by field. bool oneStepEqual(T,F)(ref T lhs, ref F rhs) if(is(Unqual!T == Unqual!F) && is(T == struct)) { bool result = true; foreach

Re: finding composed structs

2012-10-30 Thread Tobias Pankrath
On Tuesday, 30 October 2012 at 19:16:18 UTC, Dan wrote: So until this bug is fixed any time I have any dynamic array, including string in struct S, implement opEquals. When the bug is fixed I can remove them. What I didn't realize is that including an opEquals in A will cause generation of opEq

Re: __traits(compiles,...) <=> ? is(typeof(...))

2012-10-30 Thread Timon Gehr
On 10/30/2012 02:53 AM, Jonathan M Davis wrote: On Tuesday, October 30, 2012 02:22:42 Timon Gehr wrote: On 10/30/2012 01:43 AM, Jonathan M Davis wrote: On Tuesday, October 30, 2012 00:29:22 Timon Gehr wrote: On 10/30/2012 12:17 AM, Jonathan M Davis wrote: On Monday, October 29, 2012 23:38:34

Re: finding composed structs

2012-10-30 Thread Dan
On Tuesday, 30 October 2012 at 20:17:06 UTC, Tobias Pankrath wrote: Beautiful version: http://dpaste.dzfl.pl/2340d73f Beautiful indeed. Does the same approach work for generating correct versions of opCmp, assuming arbitrary order by field comparison as ordered in struct? Also hashing? Tha

Re: finding composed structs

2012-10-30 Thread Andrei Alexandrescu
On 10/30/12 4:17 PM, Tobias Pankrath wrote: On Tuesday, 30 October 2012 at 20:16:12 UTC, Tobias Pankrath wrote: In the meantime you can use this function template to compare structs field by field. bool oneStepEqual(T,F)(ref T lhs, ref F rhs) if(is(Unqual!T == Unqual!F) && is(T == struct)) {

Re: finding composed structs

2012-10-30 Thread Tobias Pankrath
Beautiful version: http://dpaste.dzfl.pl/2340d73f Y u no short circuit? Andrei Left as an exercise to the reader.

Re: finding composed structs

2012-10-30 Thread Tobias Pankrath
On Tuesday, 30 October 2012 at 21:02:22 UTC, Dan wrote: On Tuesday, 30 October 2012 at 20:17:06 UTC, Tobias Pankrath wrote: Beautiful version: http://dpaste.dzfl.pl/2340d73f Beautiful indeed. Does the same approach work for generating correct versions of opCmp, assuming arbitrary order by fi

Re: finding composed structs

2012-10-30 Thread Timon Gehr
On 10/30/2012 09:16 PM, Tobias Pankrath wrote: On Tuesday, 30 October 2012 at 19:16:18 UTC, Dan wrote: So until this bug is fixed any time I have any dynamic array, including string in struct S, implement opEquals. When the bug is fixed I can remove them. What I didn't realize is that including

Re: Threading Question

2012-10-30 Thread Sean Kelly
On Oct 30, 2012, at 11:06 AM, Alex Rønne Petersen wrote: > On 30-10-2012 19:04, Sean Kelly wrote: >> >> >> The semaphore implementation for OSX is not signal-safe. Originally, >> druntime used the signal approach on OSX and had deadlock issues in the >> signal handler (OSX semaphores wrap a

Re: Reordered class fields?

2012-10-30 Thread Peter Summerland
On Monday, 22 October 2012 at 11:06:50 UTC, Jacob Carlborg wrote: On 2012-10-22 10:48, bearophile wrote: This page says: http://dlang.org/class.html The D compiler is free to rearrange the order of fields in a class to optimally pack them in an implementation-defined manner. Consider the fie