272 questions
0
votes
3
answers
299
views
Does there exist a reversed comma operator in C?
In C, if we want to evaluate multiple statements as one, we can use the comma. This evaluates both args in order, then returns the value of the second. However, what if I want to evaluate two ...
1
vote
3
answers
118
views
Why does this macro with a comma operator fail to compile in a switch statement?
#include <stdio.h>
#define PRINT(x) (printf("%d\n", x), x)
int main() {
int a = 1;
switch (a) {
case PRINT(1): puts("Case 1"); break;
case PRINT(2)...
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 ...
2
votes
4
answers
135
views
wierd syntax with parentheses in C [duplicate]
I was given the code:
#include <stdio.h>
int main(void) {
int a = 0, b = 0, c = 0;
c = (a -= a - 5), (a = b, b + 3);
printf("a = %d, b = %d, c = %d", a, b, c); // a = 0, b =...
3
votes
2
answers
258
views
What is C++ doing when I use the comma operator in the initializer expressions?
My program was crashing, no debugger readily available, so I spiked it with printfs, narrowed it down to the (lengthy) initializer list, and tried to get it to show which initializer expression causes ...
2
votes
1
answer
109
views
JavaScript: Are (0, x.f) and (x.f) really different
x={f(){return this}}
x.f() //x
(x.f)() //x
(0,x.f)() //window
I've learned that parenthesis (grouping operator) does not apply GetValue to the expression inside it, while other operators such as , ...
0
votes
1
answer
60
views
How to only call left side of comma (,) separator
const test = (
(success) => {
console.log('SUCCESS CALLED');
},
(error) => {
console.log('ERROR CALLED');
}
);
test(); // output is **ERROR CALLED**
In ...
1
vote
3
answers
85
views
Syntax to execute some code before initializing member class objects
Is there a way to execute some code as a precursor to initializing class members? Take the following code as an example:
void enableCreationOfAObjects();
class AObject
{
public:
AObject(int i, ...
0
votes
2
answers
91
views
a parenthesis expression assigned to single lvalue [duplicate]
Why does this code compile ?
int X = (2,4);
I compiled this line with c++ replit
the second value (4) is assigned to X
2
votes
4
answers
178
views
List context and the comma operator in Perl
Having some significant confusion about what it means to "evaluate in list context", specifically related to the comma operator. In the linked perlop doc, it says: In list context, it's just ...
1
vote
2
answers
122
views
What's the syntax of following c define? [duplicate]
Following snippet is from mac sdk signal.h:
#define sigemptyset(set) (*(set) = 0, 0)
just wonder what does , 0) do?
0
votes
3
answers
359
views
c++: What does 'while (cin >> variable, variable)' exactly do?
So here's that piece of code, very basic but i just can't find any similar questions that have two variables in the while loop with cin in it.
void Perm(int start, int end, int a[]) {
//some ...
1
vote
1
answer
122
views
decltype evaluating the wrong type from an expression list
while experimenting with the answer from This post,
ended up with the following piece of code:
#include <iostream>
#include <typeinfo>
namespace Test
{
struct MyPtr
{
...
3
votes
3
answers
110
views
What would be the output obtained out of the program and how?
#include<stdio.h>
void main() {
int g = 83;
int h = (g++, ++g);
printf(“%d”, h);
}
**g++** will increment **g** after **;**
My answer: h = 84
Correct answer: h = 85
I am a ...
2
votes
1
answer
62
views
Comma operator with undeclared variable - why does it compile?
Why does this code not throw a compilation error for y being undeclared?
int x = 10, y;
printf("%d", y);
There's no expression like int y;. In my case, the console print out is 32764, ...