在rpcgen中使用unsigned long long会产生错误 [英] Use of unsigned long long with rpcgen gives error

查看:105
本文介绍了在rpcgen中使用unsigned long long会产生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件reken.x,client.c和server.c创建一个分布式系统.客户端将两个质数(即一个数)的乘积发送到服务器上的"ontbind"功能,该功能将数字分解为两个质数.当我在"reken_in"和"reken_uit"结构中将变量"getal1","antwoord1"和"antwoord2"声明为int时,这种方法可以正常工作.但是,当我使用无符号的长整型时,会出现以下错误:

I have a file reken.x, client.c and server.c to create a distributed system. The client sends the product of two prime numbers (so one number) to the "ontbind" function on the server which factorizes the number back into the two prime numbers. This works fine when I declare the variables "getal1", "antwoord1", and "antwoord2" in the "reken_in" and "reken_uit" structs as ints. However, when I use unsigned long longs I get the following error:

user@DTP12771:~/Desktop/tarbal$ rpcgen reken.x
 unsigned long long getal1;
^^^^^^^^^^^^^^^^^^^
reken.x, line 2: expected '*' or 'identifier'

如何使用unsigned long long类型进行此操作?请参考下面的代码.

How do I make this work with the unsigned long long type? Please refer to my code below.

reken.x

struct reken_in { /*input argument*/
    unsigned long long getal1;
};

struct reken_uit {
        unsigned long long antwoord1;
    unsigned long long antwoord2;
};

program BEREKEN {
    version  BERVERS{
        reken_uit ONTBIND(reken_in) =1; /*procedure nr. 1*/
         }=1;
}=0x31230000;     /*programma nummer*/

client.c

#include    <stdio.h>
#include    <rpc/rpc.h>
#include    "reken.h"
#include    <stdlib.h>

main(int argc,char *argv[])
{
//hi
CLIENT *cl;
char *server;
reken_in getallen;
reken_uit *antw;

if(argc !=3) {
    puts("aantal argumenten niet goed  <server   productPriemen>");
    exit(1);
}

server=argv[1];
getallen.getal1= strtoull(argv[2], NULL, 10);

cl=clnt_create(server,BEREKEN,BERVERS,"tcp");
if(cl==NULL) {
  printf("fout bij het zoeken naar de server");
  clnt_pcreateerror(server);
  exit(1);
}

antw= ontbind_1(&getallen,cl);
if(antw==NULL)
  puts("fout bij teruggeef parameter");

printf("Het getal %llu is het product van priemgetal %llu en %llu\n",getallen.getal1, antw->antwoord1, antw->antwoord2);
exit (0);
}

server.c

#include  <stdio.h>
#include <rpc/rpc.h>
#include <dirent.h>

#include "reken.h"
#include <math.h>

reken_uit *ontbind_1_svc(struct reken_in *g,struct svc_req *reg)
{
   static reken_uit getallen;

   unsigned long long number = g->getal1;
   unsigned long long i;
   unsigned long long fact;
    for(i = 2; i <= sqrt(number); i++) { //loop tot de sqrt
        if (!isPrime(i) || (i % 2 == 0 && i != 2)) continue;

        if ( number % i != 0 ) continue;

        fact = number / i;      //deel door de i. De i is een prime

        int prime = isPrime(fact);

        if (!prime) continue;

        getallen.antwoord1 = i;
        getallen.antwoord2 = fact;
        return (&getallen);
    }

    return (&getallen);
}

int isPrime (const long long number) {
    int i;  
    for(i = 2; i < number / 2; i++) { // 7
        if ((number % i) == 0) // 7 % 2 == 1
            return 0;
    }
    return 1;
}

推荐答案

在XDR中,未定义 unsigned long long ,而是使用: unsigned hyper hyper (已签名).有关更多详细信息,请找到规范.

In XDR, unsigned long long is not defined instead use: unsigned hyper or hyper for signed. For more details find the spec.

这篇关于在rpcgen中使用unsigned long long会产生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆