Jump to page: 1 2 3
Thread overview
Untested return values.
Oct 03, 2006
Lionello Lunesu
Oct 03, 2006
Frits van Bommel
Oct 03, 2006
Hasan Aljudy
Oct 03, 2006
Frits van Bommel
Oct 03, 2006
Walter Bright
Oct 04, 2006
Andrei Khropov
Oct 05, 2006
Lionello Lunesu
Oct 05, 2006
Kristian
Oct 05, 2006
Lionello Lunesu
Oct 05, 2006
Kristian
Oct 05, 2006
Lionello Lunesu
Oct 03, 2006
Lionello Lunesu
Oct 04, 2006
Walter Bright
Oct 04, 2006
Walter Bright
Oct 04, 2006
Hasan Aljudy
Oct 04, 2006
Pragma
October 03, 2006
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.
October 03, 2006
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.
October 03, 2006
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?)
October 03, 2006
Frits van Bommel wrote:
> Lionello Lunesu wrote:
>> What would happen if DMD would issue a compiler warning for untested return values?
> 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.

I tried this back in the '80s. It's one of those things that sure sounds like a good idea. The problem is, there are just too many cases where the return value is legitimately ignored (like printf's), so you wind up filling your code with chaff like:

	cast(void) printf( ... );

After a few dozen of those, it starts looking like a bad idea <g>.
October 03, 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.
October 03, 2006
"Frits van Bommel" <fvbommel@REMwOVExCAPSs.nl> wrote in message news:eftv4g$2ueh$1@digitaldaemon.com...
> 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.

Damn that printf :S

I actually use the printf in D quite a lot, but only because it's there. If writefln would be imported by default I'd use that instead.

L.


October 03, 2006
Lionello Lunesu wrote:

> I actually use the printf in D quite a lot, but only because it's there.If writefln would be imported by default I'd use that instead.

You're in good company then, the language's author agrees with you :-)

Seriously, it's in the wrong header. And it's pining for the fjords...

--anders
October 04, 2006
Anders F Björklund wrote:
> Seriously, it's in the wrong header. And it's pining for the fjords...

It just moved.
October 04, 2006
Walter Bright wrote:

> It just moved.

OK, so there might be a "import std.c.stdio;" to
insert in a couple of files to make them compile ?

Much better now than after the initial D release...
This should also help promote writef, which is good.

Thanks Walter,
--anders
October 04, 2006
Anders F Björklund wrote:
> Walter Bright wrote:
> 
>> It just moved.
> 
> OK, so there might be a "import std.c.stdio;" to
> insert in a couple of files to make them compile ?

I mean the parrot moved <g>.
« First   ‹ Prev
1 2 3