r/C_Programming • • Oct 15 '26

Question Why are assignment expressions lvalues?

I was reading up about lvalues and understand them now as something that resolves to an address(memory location) in the program. So a variable x is an lvalue (because it is mapped to some address on the stack) and similarly *x , x[i], strings are all lvalues. But if this is the case why is an expression a = b , not an lvalue? Here the expression would assign b to a and then return a as evident in assignments like so: int c = a = b. (I know that the equals sign is right associative and hence this would get resolved as c = (a = b), but that doesn't really invalidate the fact that a = b resolves to an address in the program?)

9 Upvotes

35 comments sorted by

View all comments

Show parent comment

2

u/flatfinger Oct 16 '26

I think the meaning of "lvalue" could be made clearer if bitfields and register-class objects were considered "pseudo-lvalues". If bitfields are not treated as being actual lvalues, then the term "lvalue" could be defined as "an expression that identifies a region of addressable storage that will be treated as a container for a value of a particular type", and "pseudo-lvalue" would be "an expression that can be used with assignment operators the same way as a real lvalue, despite the fact that it doesn't actually identify a region of addressable storage".

As it is, a lot of the "definitions" in the C Standard aren't actually definitions, but merely descriptions. A proper definition that defines X as Y will imply not only that all X are Y, but also that all Y are X. Many parts of the C Standard fall apart if one tries to treat its "definitions" that way.