gpt4 book ai didi

c - 如何在C程序中调用汇编程序- Visual Studio 2010

转载 作者:行者123 更新时间:2023-11-30 15:37:45 30 4
gpt4 key购买 nike

我需要在我的 C 程序“mainFunction.c”中调用内联 asm 函数

#include<stdio.h>
#include<math.h>

double inline __declspec (naked) __fastcall sqrt14(double n)
{
_asm fld qword ptr [esp+4]
_asm fsqrt
_asm ret 8
}

int main(){
double a=10.5;
double b;
b=sqrt14(a);
return 0;
}

当我编译这个程序时,我收到语法错误。
错误 C2143:语法错误:缺少 ';'在“{”之前
错误 C2085: 'sqrt14' : 不在形参列表中
错误 C2054:预期“(”跟随“内联”

如果我将文件名更改为“mainFunction.cpp”,则表示程序运行正常。

最佳答案

您没有指定遇到哪些错误,但函数定义似乎有点可疑。请参阅 - http://msdn.microsoft.com/en-us/library/h5w10wxs.aspx

The compiler cannot generate an inline function for a function marked with the naked attribute, even if the function is also marked with the __forceinline keyword.

尝试剥离一个无论如何都会被内联的函数也没有多大意义,内联已经为你完成了大部分工作。

关于c - 如何在C程序中调用汇编程序- Visual Studio 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22088264/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com