Interesting user mistake

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 3 11:48:55 PDT 2015


On Thu, Sep 03, 2015 at 06:44:54PM +0000, Adam D. Ruppe via Digitalmars-d wrote:
> On Thursday, 3 September 2015 at 18:42:37 UTC, H. S. Teoh wrote:
> >Now, in C, unary + actually does something -- it causes promotion of
> >narrow ints to int. I'm not sure if it does that in D as well.
> 
> what is this, javascript? a|0 :P
> 
> Seriously though, I never knew that.

I didn't either, until I googled it just now. :-D


> And I can't find where unary + is defined in D... I see the grammar
> line, but not explanation of what it actually does.
> 
> Perhaps it is meant to be self-evident!

Hmm, apparently it does *not* do type promotion in D, at least according
to this code:

	ubyte x = 1;
	pragma(msg, typeof(x));		// prints "ubyte"
	pragma(msg, typeof(+x));	// prints "ubyte"

So sounds like it's a real no-op in D.


T

-- 
Nobody is perfect.  I am Nobody. -- pepoluan, GKC forum


More information about the Digitalmars-d mailing list