Hello,
I don't know if it is really a bug but I did not know where to post my problem.
Here is a simple example:
#include <stdio.h>
void test(void)
{
int i, j, a;
printf("Begin");
i = 1;
j = 8;
// for (a = 0; a < 10; a++);
a = 4;
_asm{
Boucle:
MOV eax, DWORD PTR [a]
DEC DWORD PTR [a]
JNZ Boucle
}
}
int main(void)
{
test();
return 0;
}
When I compile this example, I have the following warning:
QuoteBuilding main.obj.
D:\Utils\PellesC\Projects\Test\main.c(5): warning #2115: Local 'i' is initialized but never used.
D:\Utils\PellesC\Projects\Test\main.c(5): warning #2115: Local 'j' is initialized but never used.
D:\Utils\PellesC\Projects\Test\main.c(5): warning #2115: Local 'a' is initialized but never used.
Building Test.exe.
Done.
I already seen a similar message on the forum (with the function search) but my problem is a little bit different (see http://smorgasbordet.com/phpBB2/viewtopic.php?t=830).
I know my example is rather stupid but I would like to understand why Pelles C does not initialize the variables which are declared initialzed correcly.
In fact, when you debug this piece of code, you can see that i, j and a variables are not initialized correctly with values defined in the code.
For example, the variable a is not equal to 4 but it has an unknow value.
Moreover, if you debug step by step the code, you could see Pelles C step over the line a = 4; :shock:
It simply ignore it.
Now, uncomment the line with for instruction and debug the piece of code.
The variable a is correctly initialized.
Is it normal?
Thanks and have a nice day.
Well probably there is some orthodoxy in the way the compiler behaves.
I suppose that if you try to initialize a variable, but don't use it, and you have the optimizations on, the compiler spares the initialization code. Is an optimization: why initialize (or create) a variable if you don't care about it?.
In the case of variable 'a', that is used, it seems a bug. It seems that the compiler optimizer ignores the assembly code (infact if you uncomment the for loop the C code signals that the variable is used and the initialized code is created).
As a workaround try using the 'volatile' qualifier:
int volatile a;