Re: char[] ported from C to char[0] in the D core library

2015-09-11 Thread badlink via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 19:37:54 UTC, Alex Parrill wrote: It's a flexible array member [1], not a pointer. Changing it to `char*` would make it incompatible with the C functions using it. [1]: https://en.wikipedia.org/wiki/Flexible_array_member TIL a new detail about C on the D

Re: char[] ported from C to char[0] in the D core library

2015-09-09 Thread badlink via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 16:59:09 UTC, Adam D. Ruppe wrote: That's typically right, but since this case does it in-place instead of pointed, the zero length array is most accurate. I didn't consider that the name is placed right after the struct. Thanks !

char[] ported from C to char[0] in the D core library

2015-09-09 Thread badlink via Digitalmars-d-learn
The struct core.sys.linux.sys.inotify.inotify_event contains the field "char[0] name" which corresponds to "char name[]" in C. Why it has been translated to "char[0]" ? For me "char*" would have been more appropriate.

Can't use toHexString

2015-07-19 Thread badlink via Digitalmars-d-learn
Hello, I get different results if I either use toHexString or crcHexString. I can't explain this behavior because crcHexString is just an alias of toHexString... Test code: http://pastebin.com/33Ye7yyJ

Re: Can't use toHexString

2015-07-19 Thread badlink via Digitalmars-d-learn
On Sunday, 19 July 2015 at 12:08:18 UTC, Adam D. Ruppe wrote: This line is illegal: return toHexString!(Order.decreasing)(crc.finish()); The std.digest.toHexString and variants return a *static array* which is static data and has a scope lifetime. It is horrendous a compiler bug that

Re: Can't use toHexString

2015-07-19 Thread badlink via Digitalmars-d-learn
On Sunday, 19 July 2015 at 12:00:23 UTC, Kagamin wrote: http://forum.dlang.org/post/ydaeytbyxdnwlbpwk...@forum.dlang.org Argh... must use the search function first... If I understand correctly in my case toHexString is returning a static char[len]. But why it gets silently converted to an

Re: Template function that accept strings and array of strings

2015-07-17 Thread badlink via Digitalmars-d-learn
On Friday, 17 July 2015 at 12:58:58 UTC, Jacob Carlborg wrote: I don't think I really understand how you want to use/call the function. Could you give an example with all the different types you want to call the function? My fault, I didn't test the variadic function enough and jumped to

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
Thank you for all answers. Removing typeof do resolve the problem when the second parameter is a simple string. However when passing an array of string the error still occur: Error: template cache.MetadataCache.hasItemParent cannot deduce function from argument types !()(string, string[]).

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
After a thorough reading of the documentation I found an even simpler solution: bool hasItemParent(T)(const(char)[] itemId, T parentId) if (is(T : const(char)[]) || is(T : const(char[])[])) { ... } Now it accepts all these: char[], const(char)[], immutable(char)[], char[][], const(char)[][]

Re: Template function that accept strings and array of strings

2015-07-16 Thread badlink via Digitalmars-d-learn
On Thursday, 16 July 2015 at 18:41:47 UTC, Gary Willoughby wrote: bool hasItemParent(A, B)(A itemId, B parentId) if (isSomeString!(A) (isSomeString!(B) || isArray!(B) isSomeString!(ElementType!(B Thank you ! I completely missed isSomeString. I think the definition can be safely

Template function that accept strings and array of strings

2015-07-15 Thread badlink via Digitalmars-d-learn
Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T is(typeof(T[]) == char))) {...} I used const(T)[] because

Re: Int to float?

2015-03-05 Thread badlink via Digitalmars-d-learn
On Thursday, 5 March 2015 at 20:16:55 UTC, anonymous wrote: On Thursday, 5 March 2015 at 20:03:09 UTC, Benjamin Thaut wrote: int someValue = 5; float sameBinary = *(cast(float*)cast(void*)someValue); The cast(void*) isn't necessary. Actually even the cast is unecessary, just use a uniform.

Are void arrays usable ?

2014-09-20 Thread badlink via Digitalmars-d-learn
Hello, I just discovered this strange behavior: struct A { void[10] x; // OK, compiles fine } class B { void[10] x; // Error: void does not have a default initializer // ! note, the message come without any line indication ! } Does this mean that void arrays are a thing or