c++ - pro*C 中没有函数体的函数声明

标签 c++ c

Based on the comments i ve changed the subject to proc code and i withdraw the claim that it is C++ syntax. Keeping the tags same; as i still hope it is similar to c++ and no ProC tag available please bear with it.

我想这是一个非常新的蜜蜂问题。但由于我没有足够的时间学习 C++ 文档,如果我能获得这方面的帮助,我将不胜感激。

我正在致力于转换类似于 C++ 语法的 pro*C 代码。

这是代码片段

#include <stdio.h>
#include <string.h>
#include <prg_codes.h>
#include <prg_defines.h>

typedef struct
{
   int errorflag;
   int slot;
} option_info;


int calc_options(currArgc,currArgv,options)
int currArgc;
char *currArgv[];
option_info *options;
{   
   int optChar;
   int invopt=0;
 while ((optChar = getopt(currArgc, currArgv, ":s:")) != -1 && !(invopt))
  {}
   /* other commands */

}  


void  main(int argc, char *argv[])
{

    option_info options;     
    int rc = 0;
    rc=calc_options(argc,argv,&options);
    /* other commands */

}

我的问题是

option_info定义为结构体,然后定义为函数并从 main 调用。还好吗?它是如何工作的?

option_info函数内部 calc_options 。因为 option_info 似乎使用了 calc_options 中定义的参数。

或者calc_options主体被写入包含部分中任何其他文件的其他位置?

最佳答案

此代码段采用古老的 K&R C 语法,该语法早于 ANSI C。然后它会奇怪地缩进,这使得乍一看就像您所描述的那样,但实际上并非如此。 calc_options 是具有三个参数的函数定义,其中第三个参数是指向 typedef option_info 的 options 指针。

这与 ANSI C 语法相同,因此更容易阅读:

int calc_options(int currArgc, char *currArgv[], option_info *options)
{
  int optChar;
  int invopt=0;
  while ((optChar = getopt(currArgc, currArgv, ":s:")) != -1 && !(invopt))
  {}
  /* other commands */
}  

“option_info 被定义为结构”(以及结构的 typedef)

“然后作为函数并从 main 调用”。 没有

“还好吗?” (但应更改为 ANSI 语法)

“它是如何工作的?” 相当不错

“option_info 是否位于函数 calc_options 内?” 这是第三个参数的类型options

“因为 option_info 似乎使用了 calc_options 中定义的参数。” 参数选项的类型

“或者 calc_options 主体被写入包含部分中任何其他文件的其他位置?”

关于c++ - pro*C 中没有函数体的函数声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34195343/

相关文章:

c++ - C++ 中相同类的不同定义 - 处理多个目标

c++ - 为什么工具栏的文本大小错误?

c++ - Visual C++ 运行时对象销毁顺序

c++ - CFLAGS 并分配多个引用?

c - C语言中的_Space是什么意思?

你能在指向数组的指针中打印内容吗?

c - C 中 1 的补码运算符

c - 为什么我必须同时导入头文件和 C 文件?

c - sscanf 和 scanset 停止读取十六进制数

c++ - 跨编译单元不同的内联成员函数是否会破坏二进制兼容性?