c++ - ‘=’ , ‘,’ , ‘;’ , ‘asm’ 或 ‘__attribute__’ 在 ‘{’ token 之前,当我使用::va_list时;

标签 c++

我包含 cstdarg 并收到以下错误:

expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token"

错误发生在以下行:

  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

关于c++ - ‘=’ , ‘,’ , ‘;’ , ‘asm’ 或 ‘__attribute__’ 在 ‘{’ token 之前,当我使用::va_list时;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24142129/

相关文章:

c++ - 将 json 文件转换为 json 对象会打乱对象的顺序

c++ - 调用方法时执行停止

c++ - 将任何数据类型/对象作为参数传递以确定其大小

c++ - std::strong_ordering 如何仅适用于零?

flex 中的 C++ 多行注释语法

c++ - 错误 C2057 : expected constant expression

c++ - 如何在 C++ 中创建不同的对象?

c++从 vector 中删除其值在一个区间内的项目

c++ - 为什么没有找到 operator<< 重载?

c++ - 定义变量时出现奇怪的错误