簡體   English   中英

當我使用:: va_list時,應在'{'標記前加上'=',',',';','asm'或'__attribute__'。

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

我包括cstdarg並得到以下錯誤:

預期的'=',',',';','asm'或' attribute '在'{'令牌之前

錯誤發生在以下行:

  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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM