哦,NO 2019-09-06 12:07 采纳率: 100%
浏览 324
已结题

forturn调用C程序函数,C程序函数为可变参数,不完全访问时出错如何解决

问题:如题

测试程序:
//====函数申明

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;

}

测试结果

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

是哪个地方出问题,求大神。。。。。。

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现