[SOLVED] lvalue required as left operand of assignment
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all, it's been a long time since I did coding in C, but thought to pick up a very old project again, just to show off what I have been working on ten years ago.
I get the error back... it seems the typecast is what upsets gcc.
Ideally, I'd rewrite the SET_BIT macro so that it will be accepted again, so that I don't have to go through thousands of lines of code to fix this...
Edit:
It would seem obvious to remove the cast from the SET_BIT macro; However, I'd have to analyze and see how and why. Naturally, I'm a lazy person as far as this goes, so what I'm curious about is why the cast appears to be invalid. (It's fairly possible that this SET_BIT is used elsewhere on a char, or maybe even a float or double... again: It will take a fair amount of going hence and forth in the code.) So: how could I safely typecast both the var and bit so that either is accepted as lvalue and rvalue respectively?
Regarding your problem, this error message is correct and as expected. If you look into the C99 standard, you'll find the following section about cast expressions:
Quote:
6.5.4 Cast operators
[...]
4 Preceding an expression by a parenthesized type name converts the value of the
expression to the named type. This construction is called a cast. (footnote 89)
(footnote 89) A cast does not yield an lvalue. Thus, a cast to a qualified type has the same effect as a cast to the
unqualified version of the type
Though, a cast is not valid on the left side of an assignment.
Thanks; It's pretty obvious when I stopped actively coding ;-) That was around 1999, hence I did not get that standard. Thanks for pointing out that I should look at the standards. While not the answer I hoped for, (I guess I'll have to try and see if removing the casts will result in big issues), I'm glad you pointed it out.
Back to programming... (oh, and I noticed I "forgot" to free(bar) in the quick-and-dirty example... :-)
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106
Rep:
I'm not sure what you are doing at a physical layer, but if you can break bits into a byte and throw them into an array you could use a ptr to an address.
I think your trying to OR the bits together to get some datatype
so, one reads only 1 (long long) integer, which is quite fast and perform certain checks based on that single integer; since it's a bitwise check/set, the method is also fairly fast and consumes little memory. There are various records with various types (all integer-based); so that these macro's are indeed widely usable.
I tagged the helpful posts as I noticed they helped me find a good solution, and quite happy that tuxdev showed how to work around the lvalue limitation regarding type casts. And marked the thread as solved. I guess this is material one does not easily figures out without some (fresh) hands-on experience. :-)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.