期望' = ',',',';',' asm '或' __attribute__ '在'{'标记之

expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token when I have using ::va_list;

本文关键字:asm 期望 attribute      更新时间:2023-10-16

我包括cstdarg,得到以下错误:

预期 ‘=’, ‘,’, ‘;’, ‘ asm"或"属性"之前"{"牌

错误发生在以下行:

  using ::va_list;

下面是cstdarg的内容:

#pragma GCC system_header
#include </usr/include/c++/4.6.3/x86_64-linux-gnu/bits/c++config.h>
#include <stdarg.h>
#ifndef _GLIBCXX_CSTDARG
#define _GLIBCXX_CSTDARG 1
// Adhere to section 17.4.1.2 clause 5 of ISO 14882:1998
#ifndef va_end
#define va_end(ap) va_end (ap)
#endif
namespace std
{
  using ::va_list;     I get the error here!
} // namespace std
#endif

和va_list在这个文件中被调用:

#include <fcntl.h>
#include <unistd.h>
#include </usr/include/c++/4.6.3/tr1/stdarg.h>

#include <stdlib.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include </usr/include/x86_64-linux-gnu/bits/errno.h>

#include "string.h"
#include "libnitro.h"
#include "nitro.h"
#define KVM_NODE "/dev/kvm"
int kvm_fd;
int kvm_vmfd;
struct nitro_vcpus vcpus;
 int kvm_ioctl(int type, ...)
{  
int ret;
void *arg;
va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(kvm_fd, type, arg);
if (ret == -1)
    ret = -errno;
return ret;
}
  int kvm_vm_ioctl(int type, ...)
 {
 int ret;
 void *arg;
 va_list ap;
va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(kvm_vmfd, type, arg);
if (ret == -1)
    ret = -errno;
return ret;
 }
 int kvm_vcpu_ioctl(int vcpu_fd,int type, ...){
 int ret;`
 `  void *arg;`
 `  va_list ap;`
  va_start(ap, type);
arg = va_arg(ap, void *);
va_end(ap);
ret = ioctl(vcpu_fd, type, arg);
if (ret == -1)
    ret = -errno;
return ret;
}


int kvm_ioctl(int type, ...)
{
  int ret;
  void *arg;
  va_list ap;
  va_start(ap, type);
  arg = va_arg(ap, void *);
  va_end(ap);
  ret = ioctl(kvm_fd, type, arg);
  if (ret == -1)
    ret = -errno;
  return ret;
}

你应该用g++而不是gcc编译你的c++代码。

此外,大多数用户(和程序)期望以.c结尾的文件(如libnitro.c)使用C语言,而不是c++语言。对于c++源代码,您应该将文件命名为libnitro.cpplibnitro.cc