Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error: invalid lvalue in assignment 1

Status
Not open for further replies.

Hemo

Programmer
Apr 9, 2003
190
US
I get error: invalid lvalue in assignment errors when trying to compile code with gcc 4.0+, this code previously compiled fine with gcc 3.x

I'm not a c nor a c++ programmer so do not understand this enough to fix it.

Could someone offer solutions for the following snippets that spawn the errors?

Each of these lines gives the error.
Code:
 (int) mAttr |= (1<<attr);

 (int) mAttr &= ~(1<<attr);

 (int)mForeCol = code - 30+Black;


I appreciate any help

 
What are the data types for attr, mAttr & mForeCol?

You can try this:
Code:
((int)mAttr) |= (1<<attr);

If that still doesn't work, then maybe try this:
Code:
((int)mAttr) |= (int)(1<<attr);
 
A cast is not an l-value, it is an r-value.

So remove all those casts on the left hand side of the expression. I've no idea what they'd achieve anyway.

What they are doing is making an r-value expression out of it, and thus causing the problem you state.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 

so I guess the fact that I don't do C or C++ coding isn't helping me any. I do not know how to remove the casts, but will start doing some reading and start my trail by fire. Thanks for the URL, it gives me a place to start.

I was hoping I could provide enough information and find a C/C++ programmer that could re-write these lines for me so they are no longer r-value expressions.
 
[tt](int) mAttr |= (1<<attr);[/tt]
becomes
[tt]mAttr |= (1<<attr);[/tt]


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
that just creates new errors.
error: invalid conversion from ‘int’ to ‘KmcVisualDefs::textAttr’


this is not my code, the author died in 2003, but we haven't had issues with it compiling and working until we moved to gcc 4.

I really appreciate you trying to help, but I'm afraid I'm too obtuse (read technicaluser and not programmer) to really figure this one out on my own.

The header file has this entry:
textAttr mAttr;


what else could I provide that might help resolve this?
 
What datatype is textAttr?
If it's compatible with an int (such as an enum), then you can cast the right side to a textAttr.
Code:
mAttr |= (textAttr)(1<<attr);

I don't know what changes were made to gcc 4.0, but maybe you were compiling at a lower warning level before? I know how to change the warning level in VC++, but not in gcc. Shouldn't be hard to find out though.
 
well, it's not a warning, it is an error. I have found referrences where the developers of gcc dropped support for 'casting an l-value', they called it a 'bogosity'.

So, I need to find a way to get 2 lines of code rewritten.

mAttr |= (textAttr)(1<<attr);

still give error:
error: invalid conversion from ‘int’ to ‘KmcVisualDefs::textAttr’

ugh.
 
> mAttr |= (textAttr)(1<<attr);
[tt]int temp = (int)mAttr | (1<<attr);
mAttr = (textAttr)temp;[/tt]

But since this is actually C++ code, that too might not work either.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 

That's it!

You rock, Salem. I was trying to do just what you wrote but wasn't thinking I could separate the bitwise.

Thanks for the assistance. I've compiled and will be testing this weekend to see if these changes are working.

You really have no idea how grateful I am.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top