C- RPC规范中struct内部2D数组的定义不起作用



我正在尝试使用RPC实现NFS。现在我的规范文件看起来像这样:(这是它的基本版本:))

struct input
{
    char command[20]; 
    char arg[10][10];   
    int numargs;
};
struct lsresult
{
    char arr[50][256];
};
program NFSPROG
{
    version NFSVERSION
    {
        lsresult ls(input) = 1;
        int cd(input) = 2;
        int mkdir(input) = 3;
        int mkfile(input) = 4;
    } = 1;
} = 0x21111111;

当我尝试使用rpcgen编译此Spec.x时,我会遇到这样的错误:

 char arg[10][10];
^^^^^^^^^^^^^^
Spec.x, line 4: expected ';'

这可能是什么原因?我不能在RPC规范中的结构内声明一个2D数组吗?(当我尝试以这种方式声明变量时出现相同的错误: int a,b,c在结构中!)

在rpcgen的终端中,您需要一系列字符串,而不是2D chars。首先,您必须打字一种参数类型

typedef string arg<10>;

然后进行这些参数的数组:

struct input
{
    string command<20>;
    arg args[10];
    int numargs;
};

lsresult类似:

typedef string filename<50>;
struct lsresult
{
    filename arr[256];
};

应该有效

最新更新