Hi: I've been able to compile the attached "helloworld.c" file converted from "helloworld.cpp". My question is how does one usually use __main() and CODE_FOR_MAIN() in tying up with the rest of the code? 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.-------------- next part -------------- A non-text attachment was scrubbed... Name: helloworld.cpp Type: text/x-c++src Size: 95 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20061106/f0e8cce0/attachment.cpp> -------------- next part -------------- A non-text attachment was scrubbed... Name: helloworld.c Type: text/x-csrc Size: 8631 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20061106/f0e8cce0/attachment.c>
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(); }
On Sun, 2006-11-05 at 19:06 -0800, Reid Spencer wrote: ...> 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.Hi Reid: I'm not using gcc for this purpose but another C compiler called AMPC. It compiles C code into Java Bytecode. What I'm missing is the C++ to JVM portion which I'm trying to use LLVM for converting C++ to C then pass it through AMPC to get the Java Bytecode. One question is does the resulting C code produced by llc will call C++ functions/methods still? It would be good if only C library functions are called since I already have the standard C library compiled by AMPC in the bytecode format. Thanks. Napi