The new ?? and ??? operators
Arlen Albert Keshabyan
arlen.albert at gmail.com
Mon Sep 24 00:49:57 PDT 2007
Stewart Gordon Wrote:
> "Derek Parnell" <derek at psych.ward> wrote in message
> news:1lomy00la8rsl.1fa6pft3qx480$.dlg at 40tude.net...
> <snip>
> > How would this evaluate in "long hand" code?
> >
> > int a = b() > c() ??? d() >= e() ??? f() != g();
>
> From what I can make out:
>
> int a = b() > c();
> if (!a) a = (d() >= e());
> if (!a) a = (f() != g());
>
> This is slightly simpler than usual because it's an initialiser (and because
> int.init happens to be 0). But in the general case where it's being
> assigned after declaration, you'd need a bit more:
>
> int temp = b() > c();
> if (!temp) temp = (d() >= e());
> if (!temp) temp = (f() != g());
> if (temp) a = temp;
>
> Stewart.
>
> --
> My e-mail address is valid but not my primary mailbox. Please keep replies
> on the 'group where everybody may benefit.
>
int a = b() > c() ??? d() >= e() ??? f() != g();
can be represented like this:
if(b() > c())
a = b();
else
if(d() >= e())
a = d();
else
if(f() != g())
a = f();
OR compiler must optimize it like this:
{
int temp = b();
if(temp > c())
a = temp;
else
{
temp = d();
if(temp >= e())
a = temp;
else
{
temp = f();
if(temp != g())
a = temp;
}
}
}
More information about the Digitalmars-d
mailing list