Mail Archives: djgpp/2000/04/13/16:39:41
Alexei A. Frounze wrote:
>But I can't understand why you talk me that my code is buggy, but it compiles
>w/o optimizations switches and works as I wanted to.
Buggy code often compiles and runs correctly. E.g., a program may incorrectly
rely on the value of an uninitialized variable being 0, and this may happen
to work when the program is compiled in a particular way. But the code is
still buggy (although the program it compiles to may not be).
>I think, it's either compiler or assembler problem because they must not accept
>faulty source code (just as point this out to me).
But the source code is valid. You can't expect the compiler to determine
whether or not it does what you intended it to do.
>I didn't figured inline ASM myself. I learnt it from this manual. And everything
>worked with it for me until the day i wanted to use the -O2 switch.
You should have used -O2 from the start, because gcc produces awful code
if you don't ask it to optimize. Also, if you use -O2 you'll find that
a lot of inline assembler is unnecessary, because gcc actually does
pretty good optimization (even if it perhaps isn't as good as Watcom)
- and if you do need assembler it can often be written in a separate
file and assembled with NASM, which is very easy. By contrast, inline
assembler in gcc is quite complicated, and someone has already pointed
out that the manual you were using has mistakes in it.
The bugs in your code are in the interface between the C and the inline
assembly. They may not cause a problem if you don't use -O2, but they
surely will as soon as the optimizer starts trying to rearrange things,
remove redundant instructions, avoid unnecessary memory access, etc.
S.
- Raw text -