digitalmars.D.bugs - [Issue 6555] New: Problem with readf
- d-bugmail puremagic.com (33/33) Aug 25 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6555
- d-bugmail puremagic.com (13/13) Aug 25 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6555
- d-bugmail puremagic.com (34/34) Apr 27 2012 http://d.puremagic.com/issues/show_bug.cgi?id=6555
- d-bugmail puremagic.com (15/15) May 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=6555
http://d.puremagic.com/issues/show_bug.cgi?id=6555
Summary: Problem with readf
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
import std.stdio: readf, writef, writeln;
void main() {
int x = 5;
writef("Give x: ");
readf("%d\n", &x);
writeln("\nx: ", x);
}
If there is no input (because that program is called by another one), readf
leaves x unchanged and doesn't raise an exception. I think this is not good.
-------------
Another problem: on Windows if you run that program from the console, and you
just hit enter, you are allowed to keep giving lines. Is this by design?
...>test
Give x:
555
123
155
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6555
Steven Schveighoffer <schveiguy yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy yahoo.com
04:19:55 PDT ---
readf returns the number of arguments filled in.
I don't think an exception is the correct path -- that is too assuming of
readf.
I think the second problem you raise is a valid concern.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6555
SomeDude <lovelydear mailmetrash.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |lovelydear mailmetrash.com
PDT ---
With 2.059, execution gives:
PS E:\DigitalMars\dmd2\samples> E:\DigitalMars\dmd2\samples\bug.exe
Give x: 5
x: 5
PS E:\DigitalMars\dmd2\samples> E:\DigitalMars\dmd2\samples\bug.exe
Give x:
std.conv.ConvException E:\DigitalMars\dmd2\windows\bin\..\..\src\phobos\std\conv.d(1779):
Unexpected '
' when converting from type LockingTextReader to type int
----------------
414878
414703
4055E1
40536F
4050BE
404990
4048F4
404849
402040
406E28
406E62
406A83
41BB1D
----------------
PS E:\DigitalMars\dmd2\samples>
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 27 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6555
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
The second problem is now fixed.
Regarding the first problem, I don't like a lot the fact that readf doesn't
throw an exception. But something like this seems to fix my problem, so I close
this bug report:
enforce(readf("%d\n", &x));
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 22 2012









d-bugmail puremagic.com 