@noreturn property

bearophile bearophileHUGS at lycos.com
Thu Oct 21 09:52:25 PDT 2010


Ezneh:

> I saw something that can be good too about returned values in Nimrod :
> http://force7.de/nimrod/tut1.html#discard-statement
> Hope the explanation is sufficient. This way, the programmer knows when he "throws away" a returned value.
> I think that could be great too. 

In C-like languages I've sometimes seen a cast to void (at the call point) of the return value:

cast(void)someFunction();

This silences the lint in some situations.

GNU C has the warn_unused_result that works in a different way, it makes the compiler generate a warning at the call point if you don't use the result of a function that has such attribute:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bwarn_005funused_005fresult_007d-attribute-2509

(Some of those attributes will probably be added to D2 as non-standard extensions if they don't become standard features first.)

Bye,
bearophile


More information about the Digitalmars-d mailing list