11,839 questions
0
votes
1
answer
45
views
Weighted smoothing based on Pascal's triangle
This code causes an erroLir Line Cintinuation error. Some reason it does not recognize the colon at the end of the case statements
//@version=6
indicator("Smooth1 with Series Input", ...
1
vote
1
answer
91
views
How can I get CLion not to indent the case lines within a switch statement?
I'm using CLion to work on some C++ project. When I write case statements, CLion always indents my case lines, like so:
switch(foo) {
case bar_1:
do_stuff(); break;
case bar_2:
...
1
vote
2
answers
186
views
GCC switch statements do not simplify on identical handling
The switch statements in the following two functions
int foo(int value) {
switch (value) {
case 0:
return 0;
case 1:
return 0;
case 2:
return 1;
}
}
int ...
6
votes
1
answer
351
views
Should switches be manually optimized with lookup tables in C++?
A lot of comments on SO suggest that compiler knows how to optimize switch statements. I've relied on this assumption to formulate my (apparently invalid) answer about lookup table refactoring. I ...
-4
votes
4
answers
334
views
How to find the longer of two strings without if, switch or ternary?
How to implement a method that receives two strings and displays a message with the longer string and its length, without using if, switch or ternary operators?
0
votes
4
answers
184
views
C Switch Function
I created a switch function, and when the user enters anything other than 1-4, I want the main() function to be called so the user can be prompted to enter a number 1-4 again. Here is my code:
#...
1
vote
1
answer
64
views
Power bi DAX query SWITCH error not working
Hi I am trying to add colour to my chart to be red if above UCL or Green if below LCL. I keep getting this error. Any advice please?
`Query (2, 2) The syntax for 'SWITCH' is incorrect.
(RateColour =
...
1
vote
4
answers
94
views
Change a Switch's item within the clause
A PS switch can, unlike an if clause, catch multiple times:
switch -regex ("flower") {
flo {write-host "String contains 'flo'"}
wer {write-host "String contains 'wer'&...
0
votes
0
answers
69
views
C# variable loses its assigned value within the same codeblock? [duplicate]
I'm new to C# and working an assignment for school where we build a console program that is essentially a container that the user can opt to put items into, see what items they have put in and then ...
2
votes
3
answers
144
views
Can someone help me understand this unexplained behaviour in C char arrays?
I have a function called escape that copies over a character array into a new one while replacing the \t and \n characters with raw characters \t and \n i.e single character '\n' becomes 2 characters '...
5
votes
0
answers
166
views
Why does clang not produce an error with an exhaustive switch case is used to return from a function?
Consider the following code:
enum class E {
ONE = 1,
TWO = 2
};
int foo(E e) {
switch (e) {
case E::ONE:
return 1;
case E::TWO:
return 2;
}
}
The C++ standard allows enum ...
3
votes
2
answers
173
views
Disabling sanity checks in generated jump tables
Consider the following switch construct. This simply switches on a variable x and prints a number.
switch (x)
{
case 1:
printf("1");
break;
case 2:
printf("2");
break;
case 3:
...
3
votes
2
answers
107
views
Replacement for using switch on enum value to access struct/union data member
I'm writing an emulator of a custom ISA 16-bit processor that has instructions with operands of different sizes in C (C23 standard). In my code, I use enum members to indicate the size of the operands,...
4
votes
1
answer
137
views
product enum class in c++
Is there a way to automatically (and at compile time) define a "product enum class" (i.e. an enum class that takes on values in the product space between two given enum classes)?
So if I ...
3
votes
1
answer
84
views
How do let and case differ in terms of lazyness?
How do let and case differ in terms of lazyness? Where do I find the information myself? And how do I experiment with it in ghci?
Some context
This incomplete piece of code is an excerpt from
Parallel ...