[LLVMdev] Convert C++ to C. What is 0x0p+0 ?
Reid Spencer
rspencer at reidspencer.com
Sat Nov 4 21:06:19 PST 2006
Hi Napi,
On Sun, 2006-11-05 at 12:40 +0800, Mohd-Hanafiah Abdullah wrote:
> Hi:
>
> I'm interested in using llvm to convert C++ code to C code.
> I used the following command to do this:
>
> % llvm-g++ -c foo.cpp -o - | llc -march=c -o foo.cbe.c
Yup, that'll do it. Although you might want to do a little optimization
otherwise you're going to get a lot of C code on output. Try passing -O2
to llvm-g++.
> In the resulting file foo.cbe.c there are many occurences of '0x0p+0'.
> What is it used for? Here's a code snippet from the file foo.cbe.c
>
> if ((ltmp_126_2 > 0x0p+0)) {
> goto ltmp_363_19;
> } else {
> goto ltmp_364_19;
> }
>
> llvm-gcc is able to compile foo.cbe.c, but I need to use another C
> compiler which gives a syntax error message for not recognizing
> the expression '0x0p+0'.
Get a new C compiler :)
The syntax in question is a C99 feature. It is printed by the C Backend
with the %a conversion token for printf. This is the representation of a
floating point number in hexadecimal. It allows certain values that
cannot otherwise be represented with a decimal number to be represented.
The C Backend needs to use this to ensure that the floating point value
it has in mind is *exactly* represented through the conversion to the C
source and then back by your C compiler.
> Thank you for your assistance.
Welcome to LLVM.
Reid.
More information about the llvm-dev
mailing list