5

In this conference, Scott Meyers starts by saying "lvalues are generally expressions you can take the address of". I am stressing the word generally: what is an lvalue that you cannot take the address of? (if it exists).

EDIT: Please provide code snippets with your answers, it make things clearer.

Community
  • 1
  • 1
qdii
  • 12,505
  • 10
  • 59
  • 116
  • 1
    Did you mean **lvalues** in your title?? – πάντα ῥεῖ Nov 08 '12 at 20:01
  • yea o.O can’t believe I wrote rvalue – qdii Nov 08 '12 at 20:06
  • I didn't get into the complete conference video, but looking at the text around I guess S.M. is really talking about 'rvalues' here. The most relevant thing I found regarding your question seems to be found here: (http://thbecker.net/articles/rvalue_references/section_05.html) – πάντα ῥεῖ Nov 08 '12 at 20:08
  • 1
    The only thing that comes to my mind is hardware specific. In TI DSPs, they've extended C/C++ such that you can have `extern cregister volatile unsigned int AMR;`, where `AMR` referes to a particular hardware register (In this case, the Addressing Mode Register). – Bill Lynch Nov 08 '12 at 20:37

2 Answers2

8

I think bitfields satisfy your conditions... I believe f.x is an lvalue, but you can't take the address of it. Interestingly, you also can't do auto & x = f.x.

C++11 Section 8.3.1 Part of Paragraph 4: Since the address of a bit-field (9.6) cannot be taken, a pointer can never point to a bit-field.

struct foo {
    int x : 3;
    int y : 3;
    int z : 3;
};

int main() {
    foo f;

    f.x = 3;
}

I'm even less sure about this other idea, but the standard says that you are not allowed to use the main function. If taking the address of main is using it, then that would also suffice. C++11 3.6.1 Paragraph 5.


And from a comment I left, I know TI extends their C and C++ compilers such that there is a storage class called cregister that you can't take the address of. (Because it refers to a physical register, which doesn't have a concept of an address).

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • 1
    Taking something's address qualifies as "ODR-use", so I think you're right about `main`. – ildjarn Nov 08 '12 at 20:53
  • @ildjarn But since `main` isn’t an lvalue anyway, how is that interesting here? – Konrad Rudolph Nov 09 '12 at 15:55
  • @Konrad : `main` is a function, and functions are lvalues. I don't see anything in §3.6.1 that says otherwise – what am I missing? – ildjarn Nov 09 '12 at 20:39
  • @ildjarn Functions are lvalues? Oh bother, C++ confuses the hell out of me. You cannot assign to a function. Why is it an lvalue then? Intuitively it shouldn’t be … just because you can take its address? (Well, parochially because §3.10 says so but this is of course not an explanation …) – Konrad Rudolph Nov 12 '12 at 08:44
0

You can take addresses from named symbols (e.g. vs. temporary instances). That's what's making up an lvalue as far I understood this explanation.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190