Untested return values.
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Tue Oct 3 13:05:14 PDT 2006
Hasan Aljudy wrote:
> Frits van Bommel wrote:
>> Lionello Lunesu wrote:
>>> What would happen if DMD would issue a compiler warning for untested
>>> return values?
>>>
>>> bool somefunc() { ... }
>>>
>>> void main() {
>>> somefunc();//warning: untested return value
>>> auto b = somefunc();//OK
>>> }
>>>
>>> Especially useful for C or OS functions returning error values or
>>> handles.
>>>
>>> L.
>>>
>>> PS. might even be worth a compiler error.
>>
>> I regularly use functions I don't need the return values of, so I
>> wouldn't like this change.
>>
>> On the other hand, Walter might stop using printf() all over Phobos... :P
>> Nah, not worth it. Besides, the fact that functions like printf() have
>> a return value is probably enough reason for Walter not to make such a
>> change.
>
> LOL, really?
> What does printf return? (what about writef?)
from http://www.cplusplus.com/ref/cstdio/printf.html (at bottom):
-----------
*Return Value.*
On success, the total number of characters printed is returned.
On error, a negative number is returned.
-----------
I suppose it could be used if want to align the next output to a
specific column without fixing all the fields to specific lengths.
Though the %n specifier could also be used for that[1].
[1] If you don't know what it does, don't worry. It's another obscure
fact of printf(): %n accepts an int* that's filled with the number of
characters printed so far. I believe it's main use is in format string
exploits :P.
More information about the Digitalmars-d
mailing list