# Variable gets corrupted

**URL:** <https://forums.digi.com/t/variable-gets-corrupted/11152>\
**Category:** Rabbit\
**Created:** [September 24, 2008, 8:37am UTC](https://forums.digi.com/t/variable-gets-corrupted/11152 "2008-09-24T08:37:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chingpaq](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@chingpaq](https://forums.digi.com/u/chingpaq)\
**Post date:** [September 24, 2008, 8:37am UTC](https://forums.digi.com/t/variable-gets-corrupted/11152/1 "2008-09-24T08:37:10Z")

</div>

I have this static variable that gets corrupted without my knowledge.

My program has a structure like this

#class static  
#memmap xmem

long variable1;  
long variable2;

#use “xxx.lib”

int variable3;  
int variable4  
char variable5  
char variable6[10]

function1()  
{  
auto int variable7;  
}  
function2()  
{  
int variable8;  
}  
function3()  
{  
variable1=variable1+1  
}

main()  
{  
variable1=0;  
while(1)  
{  
function3();  
}  
}

somehow variable1 after a while gets corrupted.

Can anyone help me on my problem?

Thanks

---

<div class="post-metadata">

**Author:** ![jono59](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jono59](https://forums.digi.com/u/jono59)\
**Post date:** [September 24, 2008, 1:06pm UTC](https://forums.digi.com/t/variable-gets-corrupted/11152/2 "2008-09-24T13:06:13Z")

</div>

I suggest you check your array does not go out of bounds and overwrite un-intended data areas.

The problem probably occurs in function 3 which needs checking/debugging, especially with regards to how you arrive at the final value for variable1. Also check that ‘long’ is correct and/or big enough to hold the result of your calculations. Also it is probably better to try variable1=Another\_Variable+1;
