开发者

Does VC++ compile down to Intel machine code or intermediate code?

I am wondering if the function pointers in VC++ can be pointed to a preinitialised memory block containing x86 machine code. Could I then execute the co开发者_开发问答de at that location using a function pointer ?

ie

void (*functionPointerToStartOfCodeSegment)(void);

functionPointerToStartOfCodeSegment = 0x4A152;

*functionPointerToStartOfCodeSegment();

Will this continue to execute the x86 code at location 0x4A152 or will it choke because it is expecting intermediate code at that location ?


Your top level question: "Does VC++ compile down to machine code or intermediate code?" You'd have to ask MS.

But given they are targeting different platforms (at least CLR and native x86), I'd guess the compiler operates in stages:

  • Parse VC++
  • Generate a high-level "intermediate" representation of the C++ code
  • a) Generate CLR code or b) generate native x86 code

I'm not sure what the connection between your main question and the detailed question is, but anyway...

Yes, you should be able to set a VC++ function pointer to point to an arbitrary block of x86 code using a cast. You have to make sure that code follows all the VC++ calling/returning conventions. If the VC++ code is compiled as CLR code, the calling conventions likely include ways to signal that the function is either more CLR code, or native x86 code. Check the MS documentation for calling conventions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜