Home > Back-end >  C language to define variables
C language to define variables

Time:10-07

I met a wonderful work of problem, a great god, the code is as follows:
Uint8_t flag=0;
Uint8_t cs=0;
Uint8_t try_count=0;
Unsigned int addr=0;
GPIO_ResetBits (GPIOA, GPIO_Pin_4 | GPIO_Pin_5);//off all the lights in
GPIO_ResetBits (GPIOB, GPIO_Pin_1 | GPIO_Pin_2);
GPIO_ResetBits (GPIOB, GPIO_Pin_5);
GPIO_ResetBits (GPIOA, GPIO_Pin_14);

Error: the code is a function of inside, there are four variables in front of the definition, when initialization, behind four lines of code can't run, and through the hardware can see phenomenon is program was stuck here, should be a mistake, when not initialise, behind four lines of code can run normally, analysis for a long time, still can not understand can run without initialization, assign the initial value will not be able to run, is this why??? Pray god give directions

CodePudding user response:

It isn't wrong, behind the front four variables was useless to ah

CodePudding user response:

It's nothing strange, the first thing you want to see what data type is uint8_t, if it is a structure or class, etc., then your usage is obviously unable to compile

You check uint8_t is what kind of, can find the correct usage

CodePudding user response:

Is the default uint8_t unsinged char, if you # include & lt; Stdint. H> , but for SCM procedures, general is defined, the original poster said initialise what do you mean? The first four variables does not use, can not understand

CodePudding user response:

These variables in the back of the procedures used to, because too much at the back of the program, I didn't get up, uint8_t must be unsinged char types, initialization is means: uint8_t flag=0; Don't initialise means: uint8_t flag;
Is the first to define variables, found that the program cannot run back, the second definition, found that the program can run in the future, this is the result of after I debug, but in the main program, but this phenomenon does not occur, as you probably know what I mean, this phenomenon in the first case, a little ways to all have no,

CodePudding user response:

Are the basic types, don't see what problem
In C, all variables can only be defined in the beginning, if there are code before

CodePudding user response:

Function is it
Int32_t Ymodem_Receive (uint8_t * buf)
{
Uint8_t flag=0;
Uint8_t cs=0;
Uint8_t try_count=0;
Unsigned int addr=0;
GPIO_ResetBits (GPIOA, GPIO_Pin_4 | GPIO_Pin_5);//off all the lights in
GPIO_ResetBits (GPIOB, GPIO_Pin_1 | GPIO_Pin_2);
GPIO_ResetBits (GPIOB, GPIO_Pin_5);
GPIO_ResetBits (GPIOA, GPIO_Pin_14);
.
...
}

CodePudding user response:

Where is jammed, GPIO first sentence? Or the fourth sentence? Don't see the logical relations, assignment or not does not affect the stack and memory usage, should not be the problem here

CodePudding user response:

May be you need BuildAll, reconstruction of the whole project,
Maybe you increase the memory test of single chip microcomputer,

CodePudding user response:

This depends on the hardware requirement for initial value, check the manual and have a look
  • Related