I am re-declaring a const int variable a few times in a switch-case statement of a function as shown following:
void functionB(type param1, type param2, ..., const int paramConstInt = 100);
void setup() {
...
}
void loop() {
...
functionA();
}
void functionA() {
...
switch(var) {
case 0: {
const int paramConstInt = 200;
...
functionB(param1, param2,..., paramConstInt);
break;
}
case 1: {
const int paramConstInt = 300;
...
functionB(param1, param2,..., paramConstInt);
break;
}
case 2: {
functionB(param1, param2,...);
...
break;
}
...
default:
// if nothing else matches, do the default
// default is optional
break;
}
}
void functionB(type param1, type param2,..., const int paramConstInt) {
...
}
Does standard C++ allow for it? I am asking so because, if I try to change one of the paramConstInt inside a switch case to 1000 or so I have a strange behaviour similar to that given by a memory leakage. I think anybody willing to replicate this oddity can do it and report. If const int is replaced by just int, the problem seems to disappear.
paramConstInt
to1000
, then this is probably due to whatfunctionB
does with that argument value. – jfpoilpret Jan 2 '17 at 14:55functionB
to check what could explain that odd behavior. – jfpoilpret Jan 2 '17 at 16:18