首页新闻找找看学习计划

Forturn调用C函数,C函数为参数可变函数,当不完全形式调用时错误,如何解决?

0
悬赏园豆:30 [待解决问题]

测试程序:
//====函数申明
extern "C" void iofunction_(const char* gathername, int* mode, void* option, int* fileptr, int* ok, ...);
void iofunction(const char* gathername, int* mode, void* option, int* fileptr, int* ok, ...);
extern "C" void iofunction_(const char* gathername, int* mode, void* option, int* fileptr, int* ok, ...)
{
iofunction(gathername, mode, option, fileptr, ok);
}

//====函数实现
void iofunction(const char* gathername, int* mode, void* option, int* fileptr, int* ok, ...)
{
va_list args;
int* args1 = NULL;
va_start(args, ok);
args1 = va_arg(args, int*);
va_end(args);

    cout << "gathername = " << gathername << endl;
    cout << "mode = "       << *mode    << endl;
    cout << "option = "     << *((int*)option)  << endl;
    cout << "fileptr = "    << *fileptr << endl;
    cout << "ok = "         << *ok      << endl;
    cout << endl;
    cout << "type = "       << args1   << endl;
    if(0x1 != *args1)
            cout << "type = "       << *args1   << endl;

}

C调用程序与结果
int main()
{
int mode = 1;
int option = 10;
int fileptr = 100;
int ok = 0;
int type = 1;
// iofunction("gathername", &mode, (void)(&option), &fileptr, &ok, &type);
iofunction("gathername", &mode, (void
)(&option), &fileptr, &ok);
return 0;
}

C程序测试结果
gathername = gathername
mode = 1
option = 10
fileptr = 100
ok = 0
type = 0x3029aeacf0
type = 699308496

fortur测试程序:

program main
character gathername
integer mode
integer option
integer fileptr
integer ok
integer a
gathername ='t'
mode=1
option=1
fileptr=1
ok=1
a=10
!call iofunction(gathername,mode,option,fileptr,ok,a) //====完全调用
call iofunction(gathername,mode,option,fileptr,ok) //====不完全调用
end program

forturn测试结果:

gathername = t
mode = 1
option = 1
fileptr = 1
ok = 1
type = 0x1
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 000000000040497D Unknown Unknown Unknown
libpthread-2.12.s 00000031CAA0F7E0 Unknown Unknown Unknown
a.out 0000000000403A6D Unknown Unknown Unknown
a.out 0000000000403831 Unknown Unknown Unknown
a.out 000000000040377F Unknown Unknown Unknown
a.out 00000000004036DE Unknown Unknown Unknown
libc-2.12.so 00000031CA21ED20 __libc_start_main Unknown Unknown
a.out 00000000004035E9 Unknown Unknown Unknown

是哪个地方出问题?
或者说是否forturn函数不支持可变参数函数调用?
跪求大神......

人面不知何处去的主页 人面不知何处去 | 初学一级 | 园豆:172
提问于:2019-10-19 14:57
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册