I'm trying to put a blcok of code in a function
this code can be called from some places in the function with asm call
the problem start when i'm using optimization compliation
i have to put a goto instruction before this block of code
example:
goto somewhere; //this line has to be here.
BlockOfCode:
DoSomthing();
_asm ret
now when there is no optimization this code works fine no problem
but when optimization is on
the compiler see the block of code as unreachable,
and so ignore it
and i get error that the label "BlockOfCode" is not recognized.
BTW i think this is kind a PellesC bug, because if there is a label preceding the code
the code is surely accessable.
anyway, i tried to turn off the optimization:
#pragma optimize(none)
goto somewhere;
BlockOfCode:
DoSomthing();
_asm ret
#pragma optimize()
but i still get the error, only if the general optimization is off, i don't get any error
is there something to do about this ?
i mean i still want optimization, but i don't want to get error on this code.
thanks ahead.
Quotei found a workaround for this issue
i'm using asm jmp instead of goto
but i still would like to know if there is other solution.
my mistake this is not working,
i found what's going on,
when optimize is on,
and the compiler reach a branch instruction: jmp, return , etc..
he skip all the code below, doesn't compile t at all,
so if there was a jump to this code from somewhere else,
there will be an error
example:
dosomething();
_asm call my_label
return;
my_label:
// anything i write here, will be ignored, when optimize is on,
//this is a bug, because if there is a label, this code can be called from somewhere else
//and it shouldn't be skipped.
exit0000:;
anyway at the meantime i found a workaround,
instead of direct jmp, i'm using indirect:
// instead of return, i'm usign jmp to exit0000 like this:
{_asm mov eax, exit0000 _asm jmp eax}
No one know the answer ? ??? :'(
If you have an unconditional return in a function, all code behind is unreachable, because return leaves the function.
Perhaps a possible workaround would be:
volatile int hide=1; // volatile to hide the value to the compiler
int main()
{
if (hide) return 0; // the compiler does not see, that hide is always true
my_label:
// so this code should not be eliminated
exit0000:;
// there is possible a return necessary
}
But this style of programming C is not very fine.
Hi whatsup,
Concerning mixing C with assembly, the best solution is to move the assembly code to a separate .asm module. Inline assembly interfers with the compiler's optimization engine.