www.digitalmars.com         C & C++   DMDScript  

D - bit expression is not a boolean ??

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
is this a compiler bug ? v0.69 win32

int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
  return 0;
 }
 return 1;
}

//bit_test.d(4): '=' does not give a boolean result

after all the bit is bool postings etc, I would have expected to be able to
write the above code
and not
 if ( (dostuff = (args.length > 2)) == true ) {
  return 0;
 }
Aug 20 2003
parent reply "Walter" <walter digitalmars.com> writes:
This is not about bit types, but more about disallowing '=' as the operator
for a boolean test, due to it being usually a typo for '=='.


"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
  bit dostuff;
  if ( dostuff = (args.length > 2) ) {
   return 0;
  }
  return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be able

 write the above code
 and not
  if ( (dostuff = (args.length > 2)) == true ) {
   return 0;
  }

Aug 20 2003
parent reply Derek Parnell <derek.parnell no.spam> writes:
On Wed, 20 Aug 2003 23:21:09 -0700 (08/21/03 16:21:09)
, Walter <walter digitalmars.com> wrote:

 This is not about bit types, but more about disallowing '=' as the 
 operator
 for a boolean test, due to it being usually a typo for '=='.


 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
 return 0;
 }
 return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be able

 write the above code
 and not
 if ( (dostuff = (args.length > 2)) == true ) {
 return 0;
 }


Or maybe .. int main( char[][] args ) { bit dostuff; if ( dostuff = (args.length > 2), dostuff ) { return 0; } return 1; } -- Derek
Aug 20 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Derek Parnell" <derek.parnell no.spam> wrote in message
news:oprt8s4jv759ej19 news.digitalmars.com...
 On Wed, 20 Aug 2003 23:21:09 -0700 (08/21/03 16:21:09)
 , Walter <walter digitalmars.com> wrote:

 This is not about bit types, but more about disallowing '=' as the
 operator
 for a boolean test, due to it being usually a typo for '=='.


 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
 return 0;
 }
 return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be



 to
 write the above code
 and not
 if ( (dostuff = (args.length > 2)) == true ) {
 return 0;
 }


Or maybe .. int main( char[][] args ) { bit dostuff; if ( dostuff = (args.length > 2), dostuff ) { return 0; } return 1; }

seen some "wonderful" uses of comma operator in if's in the past.
Aug 21 2003
parent reply "Philippe Mori" <philippe_mori hotmail.com> writes:
 This is not about bit types, but more about disallowing '=' as the
 operator
 for a boolean test, due to it being usually a typo for '=='.


 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
 return 0;
 }
 return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be



 to
 write the above code
 and not
 if ( (dostuff = (args.length > 2)) == true ) {
 return 0;
 }


Or maybe .. int main( char[][] args ) { bit dostuff; if ( dostuff = (args.length > 2), dostuff ) { return 0; } return 1; }

seen some "wonderful" uses of comma operator in if's in the past.

Maybe we should extend if (and also while) such to allows the following syntax (similar to for): if (declaration; condition) { } Otherwise yo can always do { declarations; if (condition) { } }
Aug 21 2003
next sibling parent Derek Parnell <derek.parnell no.spam> writes:
On Thu, 21 Aug 2003 10:01:43 -0400 (08/22/03 00:01:43)
, Philippe Mori <philippe_mori hotmail.com> wrote:

 This is not about bit types, but more about disallowing '=' as the
 operator
 for a boolean test, due to it being usually a typo for '=='.


 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
 return 0;
 }
 return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be



 to
 write the above code
 and not
 if ( (dostuff = (args.length > 2)) == true ) {
 return 0;
 }


Or maybe .. int main( char[][] args ) { bit dostuff; if ( dostuff = (args.length > 2), dostuff ) { return 0; } return 1; }

i've seen some "wonderful" uses of comma operator in if's in the past.

Maybe we should extend if (and also while) such to allows the following syntax (similar to for): if (declaration; condition) { } Otherwise yo can always do { declarations; if (condition) { } }

Possibly, but I was thinking more along the lines of this ... As the form if ( <EXPRESSION> ) is valid then it might be just simple enough to do ... if ( (a = b) ) in other words, if the assignment expression is enclosed in its own parenthesis, it is considered to be a simple single-term expression, which does provided a valid boolean result. -- Derek
Aug 21 2003
prev sibling next sibling parent "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Philippe Mori" <philippe_mori hotmail.com> wrote in message
news:bi2j25$31bd$1 digitaldaemon.com...
 This is not about bit types, but more about disallowing '=' as the
 operator
 for a boolean test, due to it being usually a typo for '=='.


 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:bi1me1$1n9p$1 digitaldaemon.com...
 is this a compiler bug ? v0.69 win32

 int main( char[][] args ) {
 bit dostuff;
 if ( dostuff = (args.length > 2) ) {
 return 0;
 }
 return 1;
 }

 //bit_test.d(4): '=' does not give a boolean result

 after all the bit is bool postings etc, I would have expected to be



 to
 write the above code
 and not
 if ( (dostuff = (args.length > 2)) == true ) {
 return 0;
 }


Or maybe .. int main( char[][] args ) { bit dostuff; if ( dostuff = (args.length > 2), dostuff ) { return 0; } return 1; }



 seen some "wonderful" uses of comma operator in if's in the past.

following syntax (similar to for): if (declaration; condition) { } Otherwise yo can always do { declarations; if (condition) { } }

if ( expr, var ) { .... } and for IS an extended while! my complaint was if ( bit_assign ) is an error I agree `if ( object_assign ) ...` or `if ( int_assign ) ...` are not `if ( boolean )` and thus an error (or potential error.
Aug 21 2003
prev sibling parent reply "Matthew Wilson" <matthew stlsoft.org> writes:
 Maybe we should extend if (and also while) such to allows the
 following syntax (similar to for):

 if (declaration; condition)
 {
 }

Wow, I thought it did support this! It must do.
 Otherwise yo can always do

 {
     declarations;
     if (condition)
     {
     }
 }

This is the ugly C++ workaround, but not good enough for D, methinks. Another imperfection in C++ is the fact that you can declare variables of only one type in a for statement. We would like to be able to do the following in D: for(int i = 0, j, k = 0, long l = 0, m, n = 0; ...) { } // i, j, k, l, m, n all cease to exist here Walter, does this present any serious problem for the parser? (I'm assuming it'd be a breeze for a man of your talent.)
Aug 29 2003
parent "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:biojkj$ah0$1 digitaldaemon.com...
 Maybe we should extend if (and also while) such to allows the
 following syntax (similar to for):

 if (declaration; condition)
 {
 }

Wow, I thought it did support this!

Nope.
 It must do.

Why?
 Otherwise yo can always do

 {
     declarations;
     if (condition)
     {
     }
 }

This is the ugly C++ workaround, but not good enough for D, methinks. Another imperfection in C++ is the fact that you can declare variables of only one type in a for statement. We would like to be able to do the following in D: for(int i = 0, j, k = 0, long l = 0, m, n = 0; ...) { } // i, j, k, l, m, n all cease to exist here Walter, does this present any serious problem for the parser? (I'm

 it'd be a breeze for a man of your talent.)

There are some ambiguity problems using typedef'd names after the ,.
Sep 12 2003