Local Variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Local Variables

5,451 Views
Andrew
Contributor I
Hi,
I've some problem with CW 5.0! I'm not able to initialize local varible inside functions.
For example:
 
void Kernel (INTERFACE *p)
{
unsigned char tmp = 0;
static unsigned char basetime = 0;
...
}
 
When I run the Debugger HiWave, and I stop the application inside the function, the local variables have undefined values!
 
Why Does it Happens? Is there any option to set?
 
Thanks
 
Bye
Andrew
Labels (1)
Tags (1)
0 Kudos
11 Replies

806 Views
CrasyCat
Specialist III

Hello

This pretty much depends on the context of the function.

Depending how often the local variable is accessed and on the whole context of the function, local variables might be kept into register, thus they will appear as undefined in the debugger.

CrasyCat

0 Kudos

806 Views
alex_spotw
Contributor III
Hi:

One thing that I have noticed, is that sometimes the compiler places some of the local variables in direct-access RAM or other location that the debugger indicates as 'unallocated'. The debugger therefore cannot trace them.

However, the variables are indeed allcated and the code executes without any problem.

If you need to debug those specific variables, you can declare them globally, so that the debugger can trace them.

Regards,

Alex
0 Kudos

806 Views
Andrew
Contributor I

Hello Alex,

unfortunately is not only a problem on debugging variables and viewing their values, but the application takes the wrong values!

For the standard local variables, I can initialize them in the code, but it is not possible for the static ones: I must initialize them only one time!

I use MC9S08GT32 (BDM Interface) in combination with CW5.0

Andrew

0 Kudos

806 Views
CrasyCat
Specialist III

Hello

Are you using the standard startup code delivered by CodeWarrior or did you modify it or comment something out?

static local variables are handled like global variables and need to be initialized at startup.

CasyCat

0 Kudos

806 Views
Andrew
Contributor I

I'm using the standard Start08.c file located in the SRC directory inside the CW Lib. The problem is not only in the static variables, but in the local non static, too!

I'm thinking it is a bug of the compiler/debugger!

Do you have other tips?

Regard

0 Kudos

806 Views
Guilly
Contributor I
Have you tried to init the explicitly, after their declaration ? example: unsigned char tmp;
tmp = 0;



Greetings
Sebastián
0 Kudos

806 Views
Andrew
Contributor I

Hallo Sebastián,

Yes, I've tried and it resolves the problem for the non static variables, but the problem remaines for the static ones!

thanks

 

0 Kudos

806 Views
CompilerGuru
NXP Employee
NXP Employee
Can you provide a complete project (zipped) here? I think this is most likely a configuration/debugging problem, but without an actual thing to look at I cannot say for sure. Best would be a project for the simulator.

In C, local (non static) variables are not initialized by default unless you do write the initialization (as you did in your snippet).

Another thing is the memory model. The tiny memory model does only support to init variables in the zero page. So which memory model are you using, an complete sample would realy help.
Daniel
0 Kudos

806 Views
Andrew
Contributor I

Eureka,

I've solved the problem, but I don't know how! The only way to solve the problem was to rebuild the project from scratch, using the files proposed from the wizard.

The project was build with CW 3.1 and ported to CW5.0: peraphs the problem was in the porting procedure, but I'm not sure!

Thanks to everyone

0 Kudos

806 Views
admin
Specialist II
I had the same problem.  My solution was to eliminate the following commad line arguement from the either the Compiler or Assmebler (I don't remember which) from your "Standard Settings"
 
__ONLY_INIT_SP
 
After I eliminated that, everthing was initialized correctly.
 
Hope this helps people,
Tomahawk
0 Kudos

806 Views
Lundin
Senior Contributor IV
For HC08 projects there are two options: ANSI C startup code and minimal startup code. If you pick minimal, it will only set the stack pointer and nothing more. Globals and statics will not be initialized.
0 Kudos