This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why my variable become to zero??

hi all

This is a piece of my coce,it complier by large model

In main.c

uchar volatile xdata *data ptr_reg;
unsigned char pdata g_size;

void dma_task_execute (void) small
{
  size =  g_size;
  do_something();
}

void main(void)
{
 while (1)
{
EA = 0;
dma_task_execute();
EA = 1;
}

}

In Int.c


extern unsigned char volatile xdata *data ptr_reg;
extern unsigned char pdata g_size; void int_handler(void) interrupt 2
{ EA = 0; g_size = ptr_reg[X_addr]; EA = 1; }


I found the data store into g_size in int_handler function is correct,but why g_size will become to zero when run dma_task_execute() sometimes ?? The vlaue of g_size is never will be zero,but why it will become to zero in dma_task_execute() sometimes?? Sorry my poor english any comment is welcome Best regards

Parents
  • "what value do variables declared have which are not initialized?"

    If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static storage duration is not initialized explicitly, then:

    • if it has pointer type, it is initialized to a null pointer;
    • if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    • if it is an aggregate, every member is initialized (recursively) according to these rules;
    • if it is a union, the first named member is initialized (recursively) according to these rules.

Reply
  • "what value do variables declared have which are not initialized?"

    If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static storage duration is not initialized explicitly, then:

    • if it has pointer type, it is initialized to a null pointer;
    • if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    • if it is an aggregate, every member is initialized (recursively) according to these rules;
    • if it is a union, the first named member is initialized (recursively) according to these rules.

Children