[LLVMdev] Convert C++ to C. What is 0x0p+0 ?
Mohd-Hanafiah Abdullah
napi at axiomsol.com
Sun Nov 5 19:36:17 PST 2006
On Sun, 2006-11-05 at 19:06 -0800, Reid Spencer wrote:
> 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.
The function _Z4CONTv() in helloworld.c never got called from main().
This function is supposed to be the C version of CONT() in
helloworld.cpp. Where should I insert the code in hellowrld.c to call
_Z4CONTv() ?
Thanks.
Napi
-------------------------------
#include <iostream>
int CONT()
{
std::cout << "Hello, world!\n";
}
main()
{
CONT();
}
More information about the llvm-dev
mailing list