首先说明得到此地址的原因。因为要用在线汇编,需要动态使用堆栈中的空间。最安全的方法就是使用_alloca函数。(_alloca函数决不是简单地分配一点空间那么简单,它还要判断下一个堆栈页的可读性,并负责动态增长堆栈。如果你盲目地去访问堆栈那很容易死翘翘的)尝试1:
void * (*_cdecl AllocaAddress)(size_t);
AllocaAddress=_alloca;连接器报告:找不到符号_alloca。
含入带有_alloca声明的malloc.h头文件之后,结果依然。尝试2:
生成如下代码的汇编列表
_alloca(100);
汇编成
mov eax,100;
call __alloca_probe;
欣喜中,认为编译器实际上认为_alloca是另一个符号_alloca_probe的名称。
于是写出
AllocaAddress=_alloca_probe;
编译器报错:找不到符号_alloca_probe。
现在实在是束手无策了。那位高人知道的话指点一下。
void * (*_cdecl AllocaAddress)(size_t);
AllocaAddress=_alloca;连接器报告:找不到符号_alloca。
含入带有_alloca声明的malloc.h头文件之后,结果依然。尝试2:
生成如下代码的汇编列表
_alloca(100);
汇编成
mov eax,100;
call __alloca_probe;
欣喜中,认为编译器实际上认为_alloca是另一个符号_alloca_probe的名称。
于是写出
AllocaAddress=_alloca_probe;
编译器报错:找不到符号_alloca_probe。
现在实在是束手无策了。那位高人知道的话指点一下。
解决方案 »
- 使用MFC如何读写Excel?
- 图像处理
- 苦恼~~设置socket非阻塞模式有错误?
- 哪里有VC++6.0英文原版下载?
- 如何获得当前文档模板
- 如何调用动态创建的ActiveX的方法?各位请进别客气!
- COM高手请进入?
- CRecordset:Open(AFX_DB_USE_DEFAULT_TYPE,_T("SELECT * FROM myTable"));为什么会抛出“在调用SQLFechScroll/SALExtendedFetch之前列没有绑定数据列”
- 看windows核心编程需要什么基础
- 动态生成的菜单怎样处理它的消息???
- OnInitialUpdate()函数什么时候调用?
- 如何跟踪VC程序
FARPROC GetProcAddress(
HMODULE hModule, // handle to DLL module
LPCSTR lpProcName // function name
);
为什么一定要这个函数呢?
我是没有办法啊。void MyFunc()
{
__asm
{
mov eax,100;
call _alloca;
}
}
无法通过编译,报告:找不到标号_alloca
没有其他办法的话,也只好这样了……
#pragma intrinsic
也不行。
在msdn中索引pragma下子项intrinsic中对此有详细说明
#pragma function
也不行。
在msdn中索引pragmas下子项intrinsic中对此有详细说明
我找了MSDN,里面没有提到_alloca啊?
但有关你的问题在msdn中索引pragmas下子项intrinsic中就有详细说明_alloca的文档这样找
索引malloc function
See Also节中的Memory Allocation Routines
里面就有_alloca了,不过这里没有与此问题相关的内容我用的是vs.net不是2003,所以查找方法可能有区别
我几乎翻烂了,没找着啊?倒是看见一大堆memcpy之类的
#pragma intrinsic( function1 [, function2, ...] )
Specifies that calls to functions specified in the pragma's argument list are intrinsic. The compiler generates intrinsic functions as inline code, not as function calls. The library functions with intrinsic forms are listed below. Once an intrinsic pragma is seen, it takes effect at the first function definition containing a specified intrinsic function. The effect continues to the end of the source file or to the appearance of a function pragma specifying the same intrinsic function. The intrinsic pragma can be used only outside of a function definition — at the global level.The following functions have intrinsic forms:_disable _outp fabs strcmp
_enable _outpw labs strcpy
_inp _rotl memcmp strlen
_inpw _rotr memcpy
_lrotl _strset memset
_lrotr abs strcat Programs that use intrinsic functions are faster because they do not have the overhead of function calls but may be larger due to the additional code generated.Note The _alloca and setjmp functions are always generated inline; this behavior is not affected by the intrinsic pragma.
就是上面这一句
Compile the following code from the command line with "cl -c -FAs sample.c" and look at sample.asm to see that they turn into x86 instructions CLI and STI:// pragma_directive_intrinsic.cpp
#include <dos.h> // definitions for _disable, _enable
#pragma intrinsic(_disable)
#pragma intrinsic(_enable)
void f1(void) {
_disable();
// do some work here that should not be interrupted
_enable();
}
void main() {
}
End x86 SpecificThe floating-point functions listed below do not have true intrinsic forms. Instead they have versions that pass arguments directly to the floating-point chip rather than pushing them onto the program stack:acos cosh pow tanh
asin fmod sinh The floating-point functions listed below have true intrinsic forms when you specify both the /Oi and /Og compiler options (or any option that includes /Og: /Ox, /O1, and /O2):atan exp log10 sqrt
atan2 log sin tan
cos You can use the /Op or /Za compiler option to override generation of true intrinsic floating-point options. In this case, the functions are generated as library routines that pass arguments directly to the floating-point chip instead of pushing them onto the program stack. See # pragma function for information and an example on how to enable/disable intrinsics for a block of source text.
void* myalloc(size_t len)
{
return _alloca(len);
}
我今天上网站查了才发现哪个Note...
{
/* calculates i^j, assumes that j >= 0 */ /* prolog */
__asm {
push ebp
mov ebp, esp
sub esp, __LOCAL_SIZE
// store ECX and EDX into stack locations allocated for i and j
mov i, ecx
mov j, edx
}
{
int k=1; // return value
while (j-- > 0) k *= i;
__asm { mov eax, k };
} /* epilog */
__asm
{
mov esp, ebp
pop ebp
ret
}
}
a new asm statement__asm{
...
;end asm block , allocate memory by C++
}
void* p=_alloca(lenght);
__asm{
;use p in the asm block
}