stream readf keeps producing bus error on DMD 2.046 on OS X 10.5.8
Ali Çehreli
acehreli at yahoo.com
Thu Jul 8 23:14:10 PDT 2010
RedZone wrote:
> Hi,
>
> I've been trying to use readf to read some basic text from a file... I found,
> though, that readf kept producing inexplicable bus errors. I simplified my
> code and tried to use readf on just a plain character array. No change.
> Here's the code:
>
> import std.stdio;
> //import std.file;
> import std.stream;
>
> void main()
> {
> string s1;
> int i;
> string s2;
> string s3;
>
> char[] s0 = "a 5 bc e".dup;
> auto stream = new TArrayStream!(char[])(s0);
>
> stream.readf("%s %d %s %s ", &s1, &i, &s2, &s3);
> writefln("%s %d %s %s", s1, i, s2, s3);
>
> }
>
>
> It doesn't matter how I change the input or what I use as the stream, readf
> produces this bus error. Compiling in release mode doesn't help either. What
> am I doing wrong?
>
> I'm using DMD 2.046 on Mac OS X 10.5.8.
Reading into char arrays and dropping the format string works (tried
with dmd 2.047):
char[] s1;
int i;
char[] s2;
char[] s3;
char[] s0 = "a 5 bc e".dup;
auto s = new TArrayStream!(char[])(s0);
s.readf(&s1, &i, &s2, &s3);
I hear that the streams will be (are?) deprecated. There will be
std.stdio.readf which will be in the next dmd release.
Ali
More information about the Digitalmars-d-learn
mailing list