675 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
3
answers
201
views
Is a function call returning a pointer a prvalue?
This question arouse from the question "why is const in function return type, which is a const pointer, ignored?" (const pointer, not pointer to const)
int* const Foo();
is identical to
int*...
5
votes
2
answers
318
views
Can an rvalue of a specific class type be automatically cast to an lvalue of itself?
In C++, a function with signature void f(A& a) (non-template) only binds to a lvalue.
Is it possible for an rvalue to automatically cast itself to an lvalue?
This is what I tried:
#include <...
13
votes
5
answers
2k
views
How Does the Left-Hand Side (LHS) of an Assignment Evaluate in C?
I’m working on understanding pointers in C by breaking down the language into three key areas: syntax, semantics, and idioms.
To grasp pointers, I’ve been focusing on fundamental concepts:
what’s an ...
4
votes
1
answer
79
views
Store value category of pointed-to object (for later deref)
Ok this might be a bit difficult to explain:
I want to call a function hello that has an overload for either an rvalue or an lvalue ref of type Json. This Json object is converted from a JsonKey using ...
4
votes
1
answer
109
views
Cannot return a named rvalue reference in a function with return type of lvalue reference?
In C++, a named rvalue reference is lvalue.
Why the below code yields "error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'"?
int & unmove(int &...
1
vote
2
answers
158
views
Are compound literals always lvalue?
I was reading C Notes for Professionals, in which, it claims that Compound Literals can only be lvalues. But LLMs have mixed answers upon that stating it could depend upon the context and could be ...
2
votes
1
answer
107
views
Why does passing rvalue to lvalue reference work in this case?
I was doing Leetcode when I stumbled upon this interesting technique. Here it is in short:
#include <iostream>
#include <vector>
void print(std::vector<int>& vec)
{
for (int ...
27
votes
3
answers
5k
views
Is `(expression, lvalue) = rvalue` a valid assignment in C or C++? Why do some compilers accept/reject it?
Some time ago I stumbled upon the idea of how a C construct, such as (expr0, expr1, expr2), evaluates (see "What does the comma operator , do?" for more context).
I've started experimenting ...
1
vote
1
answer
227
views
C++ Does Ranged-Based For Loop Use RValue Reference? [duplicate]
Hi I have a quick question - over here it says ranged-based for loops of the form
for ( init-statement (optional) range-declaration : range-expression )
are equivalent to the code:
{
auto &&...
1
vote
2
answers
84
views
Why does this function return a pointer instead of pointer's value in C language?
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int *array;
int size;
}Array;
Array array_create(int init_size);
int* array_at(Array *,int index);
void ...
2
votes
1
answer
76
views
Can a reference to an lvalue subroutine be used as an lvalue?
I'm having trouble using a Perl subroutine reference as an lvalue. Am I doing something wrong here, or is it not possible to do this? I'm using ActiveState Perl 5.20 on Windows.
package Warning {
...
-2
votes
2
answers
1k
views
Why am I getting an error, "non-const lvalue reference to type 'std::basic_string<char>' cannot bind to a value of unrelated type 'const char [4]'" [duplicate]
I had a queue and originally worked with strings and now I added templates to it so that if I decide to add int doubles, etc, it would still work. When using strings to add to my queue, I get an error ...
0
votes
1
answer
147
views
Question about copy constructor in return value [duplicate]
This is a code test from this.
I reproduced some of them as below:
//struct definition. All kinds of prints
struct Snitch { // Note: All methods have side effects
Snitch() { cout << "c'...
1
vote
0
answers
56
views
What is this example of modifiable lvalue found in error.h ISO C99?
I'm reading the ISO C99 Standard and this example of a modifiable lvalue object: *errno() blew me away.
Please could you tell me if this possible implementation of errno is ISO C99 compliant?
int * ...
0
votes
2
answers
158
views
Function Params as 'const T&' and 'T&&'
Need to understand and figure out how to work efficiently with these 2 definitions on lowlevel.
void func(const T& foo)
{
T bar = foo;
}
// Lets overload this
void func(T&& foo)
{
...