digitalmars.D.learn - std.file.read
- bearophile <bearophileHUGS lycos.com> Aug 01 2010
- Dmitry Olshansky <dmitry.olsh gmail.com> Aug 02 2010
- bearophile <bearophileHUGS lycos.com> Aug 02 2010
- Pelle <pelle.mansson gmail.com> Aug 02 2010
- bearophile <bearophileHUGS lycos.com> Aug 02 2010
- Dmitry Olshansky <dmitry.olsh gmail.com> Aug 02 2010
- bearophile <bearophileHUGS lycos.com> Aug 02 2010
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[]?
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:Can you tell me why std.file.read() returns a void[] instead of something like a ubyte[]?
ubyte[] data = read("trash.txt");
This code does not work for me.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:Well, 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.
AH, nor for me. Bye, bearophile
Aug 02 2010
On 02.08.2010 21:36, bearophile wrote:Pelle:Well, it magically converts to whatever array type you have. So this works: ubyte[] data = read("trash.txt");
Bye, bearophile
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 Olshansky
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









bearophile <bearophileHUGS lycos.com> 