www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to call readf

reply Petras <a a.com> writes:
Hi, I am learning how to use readf to read integers. I follow the 
example in  https://dlang.org/library/std/stdio/readf.html

The sample code use readf in following way
readf!" %d"(a);

It works when I use dmd 2.074. However, I got compile error when 
I switch to ldc2
/usr/include/d/std/stdio.d(3339): Error: tuple A is used as a type
b.d(8): Error: template instance std.stdio.readf!" %d" error 
instantiating

It turns out that I can compile the code using ldc2 if I change 
the line to
readf(" %d", &a);

So my questions are
1. Should I use ampersand? I search the web and other people use 
ampersand. But from the doc I guess that I can also pass 
arguments as ref and do need to use ampersand?

2. I also tried changing the code to readf!" %d"(&a); and ldc2 
gives me the same error. I search and the ! does something called 
template instantiation. Why it does not work here?

Thanks for your help!
May 28 2017
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 05/28/2017 07:55 AM, Petras wrote:
 Hi, I am learning how to use readf to read integers. I follow the
 example in  https://dlang.org/library/std/stdio/readf.html

 The sample code use readf in following way
 readf!" %d"(a);
Providing the format string as a template argument and being able to pass references are both 2.074 features.
 It turns out that I can compile the code using ldc2 if I change the 
line to
 readf(" %d", &a);
That's the old way that should work with 2.074 as well. Ali
May 28 2017
parent Petras <a a.com> writes:
On Sunday, 28 May 2017 at 15:00:30 UTC, Ali Çehreli wrote:
 On 05/28/2017 07:55 AM, Petras wrote:
 Hi, I am learning how to use readf to read integers. I follow
the
 example in  https://dlang.org/library/std/stdio/readf.html

 The sample code use readf in following way
 readf!" %d"(a);
Providing the format string as a template argument and being able to pass references are both 2.074 features.
 It turns out that I can compile the code using ldc2 if I
change the line to
 readf(" %d", &a);
That's the old way that should work with 2.074 as well. Ali
Thanks!
May 28 2017