[LLVMdev] Convert C++ to C. What is 0x0p+0 ?

Reid Spencer rspencer at reidspencer.com
Sun Nov 5 19:06:38 PST 2006


Hi Napi,

On Mon, 2006-11-06 at 10:44 +0800, Mohd-Hanafiah Abdullah wrote:
> Hi:
> 
> I've been able to compile the attached "helloworld.c" file converted
> from "helloworld.cpp".

Great.

> 
> My question is how does one usually use __main() and CODE_FOR_MAIN()
> in tying up with the rest of the code?

I'm not quite sure what you're asking. CODE_FOR_MAIN is defined in your
helloworld.c file as:

#define CODE_FOR_MAIN() /* Any target-specific code for main()*/
#if defined(__GNUC__) && !defined(__llvm__)
#if defined(i386) || defined(__i386__) || defined(__i386) ||
defined(__x86_64__)
#undef CODE_FOR_MAIN
#define CODE_FOR_MAIN() \
  {short F;__asm__ ("fnstcw %0" : "=m" (*&F)); \
  F=(F&~0x300)|0x200;__asm__("fldcw %0"::"m"(*&F));}
#endif
#endif

As noted in the comment, this is for target-specific code needed at the
start of main. It looks like your target needs a few assembly
instructions there.

As for the __main function, its a gcc library call required by the
compiler for program startup.  The details vary but the call is needed.
Amongst other things it will probably initialize your C++ static
constructors. 

Reid.

> 
> Attached here are the original "helloworld.cpp" and "helloworld.c"
> files.
> 
> Thanks.
> 
> Napi
> 
> On Sun, 2006-11-05 at 09:14 -0800, Reid Spencer wrote:
> > Hi Napi,
> > 
> > On Sun, 2006-11-05 at 18:30 +0800, Mohd-Hanafiah Abdullah wrote:
> > 
> > > > 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.




More information about the llvm-dev mailing list