What lvalues ​​cannot be addressed?

In this conference , Scott Meyers begins by saying that “lvalues ​​are usually expressions that you can get at.” I emphasize the word in general: what is an lvalue to which you cannot accept an address? (if it exists).

EDIT : Please provide code snippets with your answers, to make it more understandable.

+4
source share
2 answers

I think bitfields satisfy your conditions ... I believe fx is an lvalue, but you cannot take its address. Interestingly, you also cannot do auto & x = fx .

C ++ 11 Section 8.3.1 Part of paragraph 4: Since the address of the bit field (9.6) is not possible, the pointer can never point to a bit field.

 struct foo { int x : 3; int y : 3; int z : 3; }; int main() { foo f; fx = 3; } 

I'm even less sure about this other idea, but the standard says you are not allowed to use main function. If you use the address main, then this will also be sufficient. C ++ 11 3.6.1 Clause 5.


And from the comment I left, I know that TI extends its C and C ++ compilers, so there is a cregister storage class that you cannot take to address. (Because this refers to a physical register that does not have an address concept).

+7
source

You can accept addresses from named characters (e.g. against temporary instances). What made up the lvalue, as far as I understood this explanation.

0
source

Source: https://habr.com/ru/post/1444913/


All Articles