www.digitalmars.com         C & C++   DMDScript  

D - Assignments - preconditional

reply "Brian Bober" <netdemonz yahoo.com> writes:
I was following the assignment thread and decided to start a new thread
since it was getting cluttered.

I have an idea that I hope everyone will agree with.

Assignments should not be allowed inside conditionals.

Before a conditional, we could have a pre-conditional statment.

It's basically like a macro except you don't need a #define statement and it
only lasts
until the first conditional. It would also follow all the variable naming
rules except for having
a $ in front.

for instance:

typedef bit[8] byte;
byte c=0;
byte b=0;
byte a=100;
$a :  b=c*2;
while (a != $a)
{
    c+=1;
}

would be this in c++:

unsigned char c=0;
unsigned char b=1;
unsigned char a=100;
while (a != b=c*2)
{
    c+=1;
}
Feb 03 2002
next sibling parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Brian Bober" <netdemonz yahoo.com> wrote in message
news:a3ldkd$ndc$1 digitaldaemon.com...

 It's basically like a macro except you don't need a #define statement and

 only lasts
 until the first conditional. It would also follow all the variable naming
 rules except for having
 a $ in front.

 for instance:

 typedef bit[8] byte;
 byte c=0;
 byte b=0;
 byte a=100;
 $a :  b=c*2;
 while (a != $a)
 {
     c+=1;
 }

Well... int d = (b = c * 2); while (a != d) ... =)
Feb 04 2002
parent "Sean L. Palmer" <spalmer iname.com> writes:
Well, IMO Brian's is ugly and smells strongly of kludge.

Pavel, your replacement doesn't do the same thing.

I don't mind assignments in conditionals, but they should be explicitly
converted to bool (bit) or the compiler should at least issue a warning.

Sean

"Pavel Minayev" <evilone omen.ru> wrote in message
news:a3lkel$shg$1 digitaldaemon.com...
 "Brian Bober" <netdemonz yahoo.com> wrote in message
 news:a3ldkd$ndc$1 digitaldaemon.com...

 It's basically like a macro except you don't need a #define statement


 it
 only lasts
 until the first conditional. It would also follow all the variable


 rules except for having
 a $ in front.

 for instance:

 typedef bit[8] byte;
 byte c=0;
 byte b=0;
 byte a=100;
 $a :  b=c*2;
 while (a != $a)
 {
     c+=1;
 }

Well... int d = (b = c * 2); while (a != d) ... =)

Feb 04 2002
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Brian Bober" <netdemonz yahoo.com> wrote in message
news:a3ldkd$ndc$1 digitaldaemon.com...
 I was following the assignment thread and decided to start a new thread
 since it was getting cluttered.

 I have an idea that I hope everyone will agree with.

 Assignments should not be allowed inside conditionals.

That's already the case in D.
Feb 05 2002