return in void functions
Max Samukha
samukha at voliacable.com.removethis
Thu Mar 5 03:15:15 PST 2009
On Thu, 05 Mar 2009 08:40:34 +0100, grauzone <none at example.net> wrote:
>Daniel Keep wrote:
>>
>> BCS wrote:
>>> Reply to bearophile,
>>>
>>>
>>>> But this compiles with no errors:
>>>>
>>>> void foo() {
>>>> return 1;
>>>> }
>>>> void main() {
>>>> foo();
>>>> }
>>> IIRC D allows "return exp;" in a void function because it avoids special
>>> cases in template code.
>>>
>>> ReturnTypeOf!(AFn, T) fn(T)(T t)
>>> {
>>> return AFn(t,t); // AFn might return void
>>> }
>>
>> Sadly, this doesn't help if you need to cache the result before exiting.
>> I personally wish we could create void *variables*.
>
>I wonder if we'd lose anything if the void datatype was completely
>removed and replaced by a "struct void {}" declaration in object.d?
That would be awesome. Would foo() and foo(void) be distinct
overloads, one taking no arguments and the other taking a void
argument? Should voids be allowed to be declared directly or only
passed to template parameters?
>
>> -- Daniel
More information about the Digitalmars-d
mailing list