www.digitalmars.com         C & C++   DMDScript  

D - Compile error in assignment to bit field

reply larry cowan <larry_member pathlink.com> writes:
const bit mySwitch = true;
const bit[] mySwitches = [ true, false, false, true ];

int main()
{
mySwitch = false;       // "test.d(6): '1' is not an lvalue"
mySwitches[1] = true;   // compiles ok
return 0;
}

Same with v.77 and v.79
Feb 04 2004
next sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
larry cowan wrote:

 const bit[] mySwitches = [ true, false, false, true ];
 mySwitches[1] = true;   // compiles ok
Confirmed. Moreover: | mySwitches[4] = true; // also compiles ok And: | printf("%u\n", myswitches[4]); compiles also, however gives bounds checking error at runtime.
Feb 05 2004
prev sibling parent "Larry Cowan" <LarryCowan comcast.net> writes:
Note: I think there are 2 problems here:

1. The message "test.d(6): '1' is not an lvalue" is understandable (const
mySwitch has already been equated to true = 1), but not very apropos.

2. Allowing me to change const mySwitches array entries shouldn't be allowed
should it?, or do I have to "const" each entry somehow?
HELP!

"larry cowan" <larry_member pathlink.com> modified his message
news:bvs11e$1oc$1 digitaldaemon.com...
 const bit mySwitch = true;
 const bit[] mySwitches = [ true, false, false, true ];

 int main()
 {
// mySwitch = false; // "test.d(6): '1' is not an lvalue", if compile attempted
 mySwitches[1] = true;   // compiles ok
assert(mySwitches[1]); // succeeds
 return 0;
 }

 Same with v.77 and v.79
Feb 07 2004