www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6555] New: Problem with readf

reply d-bugmail puremagic.com writes:
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


--- Comment #0 from bearophile_hugs eml.cc 2011-08-25 02:53:20 PDT ---
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6555


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy yahoo.com


--- Comment #1 from Steven Schveighoffer <schveiguy yahoo.com> 2011-08-25
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6555


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com


--- Comment #2 from SomeDude <lovelydear mailmetrash.com> 2012-04-27 10:01:10
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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6555


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #3 from bearophile_hugs eml.cc 2012-05-22 15:16:31 PDT ---
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