const int redeclaration - memory leakage

I am re-declaring a const int variable a few times in a switch-case statement of a function as shown following:

void functionB(const int param1 = 100, type param2,...);

void setup() {
	...
}

void loop() {
	...
	functionA();
}

void functionA() {
	...
	switch(var) {
		case 0: {
			...
			const int param1 = 200;
			functionB(param1, param2,...);
			break;
		}
		case 1: {
			...
			const int param2 = 300;
			functionB(param1, param2,...);
			break;
		}
		case 2: {
			...
			functionB(param2,...);
			break;
		}
		...
		default: 
			// if nothing else matches, do the default
			// default is optional
			break;
		}

}

void functionB(const int param1, type param2,...) {
	...
}

If I increase one of the const-int variables too much, I have a strange misbehaviour like that given by a memory leakage. I changed the type of the variable from const int to just int and it seems that is the problem. However, I don't see why? I understand const int is re-declared inside the same function but it happens in different switch-cases. Any ideas?

Post your code.

Code is long and dirty. I believe all is needed to understand this issue has been provided in the original post.

Good luck.

If I increase one of the const-int variables too much,

How much is too much? On the Arduino Uno (and other ATMega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32768 to 32767. Do you have overflow risks in your code?

Also I notice your function definition with a default value. In c++ Parameters with default arguments have to form a contiguous group at the end of the parameter list.

@J-M-L
yes, actually

void functionB(const int param1 = 100, type param2,...);

is

void functionB(type param1, type param2, ... , const int paramConstInt = 100);

and paramConstInt is set to max 1000 or so.

@AWOL
you should not be entitled to be the "global moderator" of a forum, in my own opinion. Firstly, I am not supposed to post any code at all and you must not push me to do it in any way. Secondarily, mine is a kind of feedback since this issue might be related to a compiler fault. I know we newbie-programmers tend to blame the compiler for anything but this is actually a subtle matter. Good luck to you.

Thank you for your opinion.
It has been noted.
(For the record I'm 'a' global moderator, not 'the' global moderator)
Admins, can you remove my moderator superpowers, please?

@OP you can send as many PMs as you like, but until you post sufficient code to allow others to reproduce your problem, you're simply wasting time.

AWOL, you can be ironic about it as long as you like but a serious moderator DO NOT FILL 3 posts with useless sentences...

alberto_mio:
@
@AWOL
you should not be entitled to be the "global moderator" of a forum, in my own opinion. Firstly, I am not supposed to post any code at all and you must not push me to do it in any way. Secondarily, mine is a kind of feedback since this issue might be related to a compiler fault. I know we newbie-programmers tend to blame the compiler for anything but this is actually a subtle matter. Good luck to you.

Ridiculous statement. Are we expected to take your word that you have found a compiler fault? Of course not. You should produce an SSCCE that illustrates the fault then your peers can check your assertion. The code you published is not an SSCCE. Now you may have found a compiler bug but my experience says you probably have not.

As far as your attack on AWOL is concerned. I don't always agree with the way AWOL responds but if you have a beef then report him to the moderators (AWOL is not the only moderator). Then grow a thicker skin.

Alberto - as i pointed your snippet was already not correct, you did not tell us the full story. what else is wrong in your code that we don't know about?

You have rights to have an opinion, and a long, complex, private code... but unless you post a full working code demonstrating your claims that Men of goodwill (moderator or not) can duplicate and help you out on their free time, then that remains your personal undocumented claim... you can store this with your opinion, because it does not help you nor anyone.

@stowite
“Ridiculous statement” is possibly yours and don’t go personal with “grow a thicker skin”.
This is an open community to which anyone contributes according to his knowledge and expertise. So, don’t be bullish with newbies, please.
I just dealt with technical issues even when talking to Mr. AWOL since I tried to explain how a moderator is largely expected to rule the discussion and participate to it.

You've got a problem(or at least you think you have) and you're only allowed one post every five minutes.

You could use those posts sensibly, and get your problem fixed, or you can whine and waste time, and eventually get a forum timeout for time-wasting.

Your choice.

alberto_mio:
"Ridiculous statement" is possibly yours and don't go personal with "grow a thicker skin".
This is an open community to which anyone contributes according to his knowledge and expertise. So, don't be bullish with newbies, please.

If you look at my post count you will see that I am a relative newbie to Arduino. I am not a newbie to C and C++ having earned my living using them for many many years..

I just dealt with technical issues even when talking to Mr. AWOL since I tried to explain how a moderator is largely expected to rule the discussion and participate to it.

No you didn't. You made a personal attack on him by asserting that he should not be a global moderator.

Alberto

Firstly, I am not supposed to post any code at all and you must not push me to do it in any way.

Why do you think you are not supposed to post any code? AWOL is joining your thread as a participant, not using any moderator super power. What he is asking for is totally reasonable given you did not document your claim.

Secondarily, mine is a kind of feedback since this issue might be related to a compiler fault.

It’s - in my humble personal opinion - a very poor kind of feedback… but that’s just my opinion.

AWOL, as a moderator, it should take 5 secs to you to realise if someone is willing to share his private code or not. Now, it is clear that I am not. Back to my original post, I repeat that I just wanted to inform the open-community that I met a problem and I also described in details how I did. I am not looking for an answer here and now - unless someone already knows about it - but my greatest hope is that someone else may find the root of a similar problem in the same matter I pointed out and possibly report it here together with mine.
Regarding “forum timeout for time-wasting”, I believe the “global moderator” caused time-wasting much more than me.

alberto_mio:
Firstly, I am not supposed to post any code at all and you must not push me to do it in any way.

You will have to write a representative example that shows the behaviour if you really want us to look at it and be able to reproduce it.

Alberto - stop wasting everyone's time here in egocentric view of the role of the community and this forum.

Either you want to warn the community of a bug, and you do your homework and research, create a small code example highlighting the problem, go file this in the GitHub of the arduino team to explore and notify the community - that's a good practice.

But Your claim here is unsubstantiated, we can't help because we can't reproduce. And You are not willing to help by bringing evidence of the behavior you describe... what do you expect?

so you are by yourself in your rant against this unfair world... go dig in your code yourself. By your own admission your code is dirty, every programmer knows what lurks in dirty code...

alberto_mio:
Back to my original post, I repeat that I just wanted to inform the open-community that I met a problem

Thanks for informing.

alberto_mio:
and I also described in details how I did.

No, you unfortunately did not.

Forum timeout issued for time-wasting.
Thread locked.

alberto_mio:
I am re-declaring a const int variable a few times in a switch-case statement of a function as shown following:

No you aren't. You are declaring different constants.

alberto_mio:
AWOL, as a moderator, it should take 5 secs to you to realise if someone is willing to share his private code or not. Now, it is clear that I am not.

Take it somewhere else, buddy.

You want help on unposted code. Take it to some forum where they debug hypothetical problems on code you aren't prepared to post.