About 5744p stack initial

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

About 5744p stack initial

698件の閲覧回数
liujinhang
Contributor III

hi,

if there is a function likes bellow:

void Func_A(void)

{   

   unsigned int a;   

   unsigned int b = 0;

}

 

can we make sure the local variables 'a' and 'b' are all zero when Func_A is called?

if we can't make sure 'a' will be zero, how can we do to make sure that?

i know one way of coding like below:

unsigned int a = 0;   

but some times i can not make sure all local variables are all initialed.  how can i do to make compiler to initial all un-initialled local variables to zero before running the functions?

 

PS: my compiler is Green Hills.

ラベル(1)
0 件の賞賛
返信
2 返答(返信)

569件の閲覧回数
stanish
NXP Employee
NXP Employee

Hi,

I'm not aware of such a a feature/switch.

User is responsible for the initialization of all the local variables. These variables exists on stack or a register.

Anyway compiler should issue a warning in case there is an uninitialized variable. So I'd suggest you to start with these warnings.

Stan

0 件の賞賛
返信

569件の閲覧回数
davidtosenovjan
NXP TechSupport
NXP TechSupport

Hi, it is rather question for GreenHills but in principle only “unsigned int a = 0;” or further initialization in code will guarantee unitialized local variable is cleared.

0 件の賞賛
返信