I am facing a very tricky scenario. I am using s21x i have found a code as follows
the definition as in file1.c
unsigned char value[12];
and the declaration as follows
extern unsigned char value[11];
clearly both do not match and it is wrong and i am facing an issue where the value modified in file2.c as
value[11] = some value; is behaving randomly that is it goes to some unexpected value. specifically value[11] is behaving randomly. Since the issue is difficult to reproduce can i assume that above mismatch can be a problem. How the code will behave in above cases. Please help.
Solved! Go to Solution.
Hi,
it is absolutely nonsense to discuss one static array variable with two different sizes. Have you checked variables mapping and size in the map file.
If the variable is defined as
unsigned char variable[11] then it is nonsense to address variable[11]=xxx; We know that array which is defined with this has members [0]..[10].
But you have also to think about qualifier extern. It does not alocate sace. It only says that there is an object of this name defined globally somewhere.
I really suggest to use both definitions with the same size [12]. Then you will get no warning message.
BTW; extern only says that there is some object of the name defined globally somewhere. Because you use extern unsigned char value[11]; in the test.c file you will receive warning L1827 Symbol value has different size in the main.c.o (12 bytes) and test.c.o (11 bytes)
and warning
C1857 Acces out of range.
All messages are OK and in the reality there is a global array value[12] because there is a global definition of this array. If you look into debugger and you check the size of the value you will see 12 members. Also in the map file you will find 12 members.
Best regards,
Ladislav
Request to give some advice.
Hi,
I do not believe the compiler was able to accept an approach you use. If you look into attachment then there is a error message presented after compilation.
I believe you have defined the variable "value" as a global variable. In this case there is an error message reported. However, if you create the variable "unsigned char value[12];", for example, in the main function, then it is not the same variable as variable defined in the header file but it is local variable for function main.
It would be good to know what you exactly doing.
Best regards,
Ladislav
Any help or advice??
Hi,
it is absolutely nonsense to discuss one static array variable with two different sizes. Have you checked variables mapping and size in the map file.
If the variable is defined as
unsigned char variable[11] then it is nonsense to address variable[11]=xxx; We know that array which is defined with this has members [0]..[10].
But you have also to think about qualifier extern. It does not alocate sace. It only says that there is an object of this name defined globally somewhere.
I really suggest to use both definitions with the same size [12]. Then you will get no warning message.
BTW; extern only says that there is some object of the name defined globally somewhere. Because you use extern unsigned char value[11]; in the test.c file you will receive warning L1827 Symbol value has different size in the main.c.o (12 bytes) and test.c.o (11 bytes)
and warning
C1857 Acces out of range.
All messages are OK and in the reality there is a global array value[12] because there is a global definition of this array. If you look into debugger and you check the size of the value you will see 12 members. Also in the map file you will find 12 members.
Best regards,
Ladislav
Thank you very much for the reply. I will show you the example project the way i have written. Can you please look into the project and advice me. I am getting the warning access out of range C1857. Briefly i will write the code here
main.c
unsingned char value[12];
void main(void)
{
testfunction();
}
test.c file
extern unsigned char value[11];
void testfunction(void)
{
value[11]=12;
}
I agree that the way i have written the code is wrong. Please suggest me whether value[11] exists or not or the behaviour is undefined.