[LLVMdev] Convert C++ to C. What is 0x0p+0 ?
Bill Wendling
isanbard at gmail.com
Sun Nov 5 13:48:17 PST 2006
On Nov 5, 2006, at 2:30 AM, Mohd-Hanafiah Abdullah wrote:
> On Sat, 2006-11-04 at 21:06 -0800, Reid Spencer wrote:
>>> 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.
>
> Hi Reid:
>
> Thank you for your email. I need to use this C compiler that only
> supports ANSI C 1989. What is the equivalent of '0x0p+0' in C89 ?
> Is there any way around this?
>
$ cat t.cpp
#include <iostream>
int main(int argc, char** argv)
{
std::cout << "0x0p+0 == " << 0x0p+0 << "\n";
}
$ ./t
0x0p+0 == 0
I supposed you could always hack the CBE to have it produce
traditional floating point numbers (like 0.0 or whatever) using "%f"
instead of "%a". However, you might have problems with precision
during comparisons. I.e., if you have something like "if (a ==
37.927)", it may not work.
-bw
More information about the llvm-dev
mailing list