DSPRelated.com
Forums

Static vars declaration

Started by alberto_reit July 7, 2004
Thanks Harrold to you for your answer but I've discovered that the
problem was an interrupt that was going to change some unsaved
register. Do you know how can avoid this problem? (i'm new in
motorola uP development). I have got another question if someone can
answer to me: I've declared 2 functions ex:
void FunctionA(void)
{
static VarA;

VarA++;
}

void FunctionB(void)
{
static VarA;

VarA++;
}

main
{
FunctionA();
FunctionB();
}

When I'm going to call FunctionB function it increments the same
variable declared in FunctionA does anyone know why? Is a bug bug of
CW V6.0 or it is mine?

Thank you very mutch
Alberto




Dear Alberto,

It may be a debug displaying error rather than a runtime
error. I'd try adding some debug information to be
absolutely sure:

#include <stdio.h>

int * FunctionA(void)
{
static int VarA = 0;
VarA++;
return &VarA;
}

int * FunctionB(void)
{
static int VarA = 0;
VarA++;
return &VarA;
}

void main(void)
{
int * p1;
int * p2;
p1 = FunctionA();
p2 = FunctionB();
printf("VarA (FunctionA) : %d\n", *p1);
printf("VarA (FunctionB) : %d\n", *p2);
}

Regards,
--
Henk-Piet Glas Support Engineer
-----------------------
E-mail: Altium Software BV
Voice: +31-33-455 85 84 Saturnus 2
Fax: +31-33-455 55 03 3824 ME Amersfoort
WWW: http://www.altium.com The Netherlands
--------[Altium - Making Electronics Design Easier]--------