digitalmars.D.learn - std.file.read
- bearophile (4/4) Aug 01 2010 Can you tell me why std.file.read() returns a void[] instead of somethin...
- Dmitry Olshansky (10/16) Aug 02 2010 Well, it magically converts to whatever array type you have. So this
- bearophile (4/6) Aug 02 2010 In more than tree years of nearly daily usage of D I have not even tried...
- Pelle (4/14) Aug 02 2010 Neither does this.
- bearophile (4/8) Aug 02 2010 AH, nor for me.
- Dmitry Olshansky (9/20) Aug 02 2010 Hm... it doesn't ...
- bearophile (6/8) Aug 02 2010 This is a small known problem of D newsgroups. To partially cope with it...
Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]? (Performing a cast(ubyte[]) in SafeD can be a problem. I presume in SafeD I have to use other safer functions to load binary data, like slurp() or something similar.) Bye, bearophile
Aug 01 2010
On 02.08.2010 5:23, bearophile wrote:Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]?Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt"); It's interesting fact deserving further investigation. It seems that void[] arrays are converted implicitly, this also works: void[] tr = malloc(20)[0..20]; data = tr;(Performing a cast(ubyte[]) in SafeD can be a problem. I presume in SafeD I have to use other safer functions to load binary data, like slurp() or something similar.) Bye, bearophile-- Dmitry Olshansky
Aug 02 2010
Dmitry Olshansky:Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt");In more than tree years of nearly daily usage of D I have not even tried to write that code :-) Thank you, bearophile
Aug 02 2010
On 08/02/2010 10:23 AM, Dmitry Olshansky wrote:On 02.08.2010 5:23, bearophile wrote:This code does not work for me.Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]?Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt");It's interesting fact deserving further investigation. It seems that void[] arrays are converted implicitly, this also works: void[] tr = malloc(20)[0..20]; data = tr;Neither does this. I am running 2.047, am I doing something wrong?
Aug 02 2010
Pelle:AH, nor for me. Bye, bearophileWell, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt");This code does not work for me on dmd 2.047.
Aug 02 2010
On 02.08.2010 21:36, bearophile wrote:Pelle:Hm... it doesn't ... Ouch, I was very much sure the unittest run, but unfortunately it didn't (it was some other debug output then...). Dang, DMD does not even type check the unitest code when the compiler option not passed. Again, my apologizes. -- Dmitry OlshanskyAH, nor for me. Bye, bearophileWell, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt");This code does not work for me on dmd 2.047.
Aug 02 2010
Dmitry Olshansky:Dang, DMD does not even type check the unitest code when the compiler option not passed.This is a small known problem of D newsgroups. To partially cope with it at the end of each module I add something like: unittest { printf(__FILE__ ~ " unittest performed."); } But among the enhancement requests of the D unit-testing there need to be a better solution to that problem too. Bye, bearophile
Aug 02 2010