也影响,因为符号的命名规则不一样,链接时名称不同会找不到符号。
从生成的汇编上看,两个符号分别如下,名称不对应的话,链接会失败。
c_function
?stdcall_function@@YAHXZ
//用命令行 CL.exe /Fs sym.cpp 生成sym.asm
extern "C" {
int c_function() {return 1;}
}
int __stdcall stdcall_function() {return 2;}
int main() {
return c_function() + stdcall_function();
}
/* sym.asm
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.37.32825.0
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC c_function
PUBLIC ?stdcall_function@@YAHXZ ; stdcall_function
PUBLIC main
pdata SEGMENT
$pdata$main DD imagerel $LN3
DD imagerel $LN3+31
DD imagerel $unwind$main
pdata ENDS
xdata SEGMENT
$unwind$main DD 010401H
DD 06204H
xdata ENDS
; Function compile flags: /Odtp
_TEXT SEGMENT
tv64 = 32
main PROC
; File Z:\t\sym.cpp
; Line 6
$LN3:
sub rsp, 56 ; 00000038H
; Line 7
call c_function
mov DWORD PTR tv64[rsp], eax
call ?stdcall_function@@YAHXZ ; stdcall_function
mov ecx, DWORD PTR tv64[rsp]
add ecx, eax
mov eax, ecx
; Line 8
add rsp, 56 ; 00000038H
ret 0
main ENDP
_TEXT ENDS
; Function compile flags: /Odtp
_TEXT SEGMENT
?stdcall_function@@YAHXZ PROC ; stdcall_function
; File Z:\t\sym.cpp
; Line 5
mov eax, 2
ret 0
?stdcall_function@@YAHXZ ENDP ; stdcall_function
_TEXT ENDS
; Function compile flags: /Odtp
_TEXT SEGMENT
c_function PROC
; File Z:\t\sym.cpp
; Line 3
mov eax, 1
ret 0
c_function ENDP
_TEXT ENDS
END
*/
【 在 z16166 的大作中提到: 】
: calling convention影响运行时(可能崩掉),不影响编译时
--
FROM 171.221.52.*