lvalue

Why isn't the result of this cast an lvalue?

大兔子大兔子 提交于 2019-12-01 04:03:26
问题 I need some advice with this strange behavior – lets have this code: int ** p; This compiles without any trouble: p++; But this: ((int**)p)++; Gives me this error message: “error: lvalue required as increment operand” . I am casting to p to the type it already is, nothing changes, so what is the problem? This is simplified version of problem I came across, when I was trying to compile one old version of gdb . So I suppose, that this worked and something changed. Any idea what is wrong with

Confusion about an error: lvalue required as unary '&' operand [duplicate]

浪子不回头ぞ 提交于 2019-12-01 03:34:24
问题 This question already has answers here : Not able to understand error condition wrt lvalues (3 answers) Closed 5 months ago . I have been trying to understand pointer concepts by writing simple code, and I got an error problem, and it seems like I couldn't solve it or understand it. #include <stdio.h> int *foo(void); int main(void) { printf("%d\n", *foo()); return 0; } int *foo(void) { static int num = 1; ++num; return &(++num); } Here is the error message. error: lvalue required as unary ‘&’

How to access an object's storage through an aggregate

不羁岁月 提交于 2019-12-01 02:45:19
In "Lvalues and rvalues", [basic.lval] (3.10), the C++ standard contains a list of types such that it is valid to "access the stored value of an object" through a glvalue of such a type (paragraph 10). Specifically, it says: If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: the dynamic type of the object, [some unimportant details about CV and signed/unsigned] an aggregate or union type that includes one of the aforementioned types among its elements or nonstatic data members (including,

What's the meaning of “identity” in the definition of value categories in C++

≯℡__Kan透↙ 提交于 2019-12-01 02:07:43
问题 In short, you can just answer the part about identity, thanks. My main focus of this question is start from 2. about identity, I just tried to provide context/background of my current understanding so it may help you decide the depth when you're writing your answer. I want to understand the big picture of type system and value categories in C++. I've searched/read many questions and resources online, but everyone has a distinct explanation, so I'm really confused. I'll list the part I can't

How to access an object's storage through an aggregate

十年热恋 提交于 2019-11-30 22:31:20
问题 In "Lvalues and rvalues", [basic.lval] (3.10), the C++ standard contains a list of types such that it is valid to "access the stored value of an object" through a glvalue of such a type (paragraph 10). Specifically, it says: If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: the dynamic type of the object, [some unimportant details about CV and signed/unsigned] an aggregate or union type that

In C++11, how can I get a temporary lvalue without a name?

北城以北 提交于 2019-11-30 14:37:29
问题 I have a traditional C lib and a function ( setsockopts ) wants an argument by pointer. In C++11 (gcc 4.8), can I pass this argument without initializing a named variable? I have the following, non-satisfying solution: #include <iostream> #include <memory> int deref(int const * p) {return * p;} using namespace std; int main() { int arg = 0; cout << deref(& arg) << endl; // works, but is ugly (unnecessary identifier) cout << deref(& 42) << endl; // error: lvalue required as unary ‘&’ operand

Can an lvalue reference non-type template parameter be inferred?

不打扰是莪最后的温柔 提交于 2019-11-30 12:45:22
I have the following code, which I cannot get to work: struct foo {}; foo foo1 = {}; template <foo& F> class FooClass {}; template <foo& F> void foobar(FooClass<F> arg) { } int main() { FooClass<foo1> f; foobar(f); } The error is: main.cpp:14:5: error: no matching function for call to 'foobar' note: candidate template ignored: substitution failure : deduced non-type template argument does not have the same type as the its corresponding template parameter ('foo' vs 'foo &') Is it at all possible to infer lvalue reference template parameters? If so, how should it be done? This is precisely

PODs, non-PODs, rvalue and lvalues

旧街凉风 提交于 2019-11-30 12:38:22
问题 Could anyone explain the details in terms of rvalues, lvalues, PODs, and non-PODs the reason why the first expression marked below is not ok while the second expression marked below is ok? In my understanding both int() and A() should be rvalues, no? struct A {}; int main() { int i; A a; int() = i; //Not OK (error). A() = a; //OK. return 0; } 回答1: Rvalues are what you get from expressions (a useful simplification taken from the C standard, but not worded in C++ standardese). Lvalues are

Correlation between specifier and qualifier?

廉价感情. 提交于 2019-11-30 12:35:55
const and volatile are called cv-qualifier by the C spec. What is exactly defference between specifier and qualifier ( cv-qualifier )? Is a qualifier is a specifier as well? Is it necessarry that qualifier is with an lvalue only? What are qualifiers other than cv-qualifier ? Does my above understanding make any sense? Most of it doesn't make sense. Specifier and qualifier are defined in the C++ standard. Qualifier is just an integral part of a specifier . For example, type specifier in a declaration can include cv-qualifiers . I don't see the reason to quote everything from the standard on

In C++11, how can I get a temporary lvalue without a name?

前提是你 提交于 2019-11-30 11:12:30
I have a traditional C lib and a function ( setsockopts ) wants an argument by pointer. In C++11 (gcc 4.8), can I pass this argument without initializing a named variable? I have the following, non-satisfying solution: #include <iostream> #include <memory> int deref(int const * p) {return * p;} using namespace std; int main() { int arg = 0; cout << deref(& arg) << endl; // works, but is ugly (unnecessary identifier) cout << deref(& 42) << endl; // error: lvalue required as unary ‘&’ operand cout << deref(& * unique_ptr<int>(new int(42))) << endl; // works, but looks ugly and allocates on heap