当代码中不存在代码行时如何解决Visual Studio 2010 C ++中的错误C2719 [英] How to solve error C2719 in visual studio 2010 c++ when no code line exist in code

查看:312
本文介绍了当代码中不存在代码行时如何解决Visual Studio 2010 C ++中的错误C2719的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个我从同事那里收到的项目。我收到以下错误:

I am building a project I have received from a colleague. I am receiving the following error:


.. \HelperFunctions\disp.cpp(130):错误C2719:'viewpoint':带有__declspec(align('16'))的形式参数将不会对齐

..\HelperFunctions\disp.cpp(130): error C2719: 'viewpoint': formal parameter with __declspec(align('16')) won't be aligned

我正在跟踪 disp.cpp 行130只是发现这是函数的结尾,我在这一行中所拥有的只是:

I am following clues to disp.cpp line 130 only to find this is the end of a function and all I have in this line is:

}

此链接据我了解,这可能与函数定义有关,但是我无法完全理解是否有任何错误。我已经注释了该函数的所有不必要元素,并将其简化为:

Following this link it is my understanding this might be an issue with the function definition, but I could not fully understand if there is anything wrong. I have commented all unnecessary elements of the function and reduced it to:

std::vector< int > HPR (typename pcl::PointCloud<PointT>::ConstPtr source,pcl::PointXYZ viewpoint, double param)
{
    //commented section
    std::vector< int > indices;
    //commented section
    return indices;
}

仍然出现相同的错误。


  • 我想念什么?

  • 我该如何解决?

PS
我是C ++的新手,正在使用 PCL API 来开发Visual Studio 2010。

P.S. I am new to C++ and working on visual studio 2010 with PCL API.

推荐答案

在搜索 pcl :: PointXYZ ,我发现它实际上是基于特征库。 (我在源代码中看到了很多 EIGEN 宏。)

After googling the pcl::PointXYZ, I found out that it's actually based on the Eigen library. (I saw a lot of EIGEN macros in the source code.)

EIGEN库试图获得最佳性能使用特殊的 SSE 说明。 AFAIK,这些SSE指令要求数据必须正确对齐(例如,地址是16的倍数)。

The EIGEN library tries to obtain best performance using special SSE instructions. AFAIK, these SSE instructions require that the data has to be aligned appropriately (e.g. that addresses are multiples of 16).

这可能会干扰

std::vector<int> HPR(
  typename pcl::PointCloud<PointT>::ConstPtr source,
  pcl::PointXYZ viewpoint, double param);

调用函数时,参数可能会移交给CPU寄存器,但通常(尤其是在Intel x86上) CPU)将它们压入堆栈,在此函数使用某个基本指针访问它们,例如Intel的CPU获取BP寄存器(16位),EBP(32位)或RBP(64位)。

When a function is called the arguments may be handed over in CPU registers but usually (especially on Intels x86 CPUs) they are pushed to the stack where the function accesses them using a certain base pointer, for Intels CPUs e.g. obtaining the BP register (16 bit), EBP (32 bit), or RBP (64 bit).

有关Eli Benderskys的更多信息 x86-64上的堆栈框架布局

More about this on Eli Benderskys Stack frame layout on x86-64.

但是,将数据推送到堆栈可能不允许按要求对齐数据(而不会破坏被调用函数的二进制签名)。因此,编译器将引发错误C2719。

However, pushing data to stack may not allow to align the data as required (without breaking the "binary signature" of the called function). Thus, the compiler throws the error C2719.

如果将函数的2 nd 参数从value更改为reference,则表示引用为原始变量已移交。 (尽管从技术上讲这可能并不完全正确,但我认为它是在移交原始变量的地址而不是堆栈上的副本。)为防止意外覆盖引用变量的内容,请使用 const 引用:

If the 2nd parameter of the function is changed from value to reference this means the reference of the original variable is handed over. (Although this may technically not fully correct, I imagine it as handing over the address of the original variable instead of a copy on stack.) To prevent accidental overwriting the contents of the referenced variable, a const reference can be used:

std::vector<int> HPR(
  typename pcl::PointCloud<PointT>::ConstPtr source,
  const pcl::PointXYZ &viewpoint, double param);

由于引用,使用的原始变量要么正确对齐(否则会导致另一个错误)在另一行源代码中)。作为参考,不再需要特殊的对齐方式。

Due to the reference, the original variable is used which is either correcly aligned (or would cause another error at another line of source code). For the reference, no special alignment is required anymore.

要使用 const (或非 const )引用而不是值可能会对性能产生积极影响。如果参数类型的大小比机器字大得多(即适合寄存器的大小),则值得传递引用而不是复制值。 pcl :: PointXYZ 考虑:

To use a const (or non-const) reference instead of a value may have additionally a positive performance effect. If the parameter type is something with significant greater size than a "machine word" (i.e. something which fits into a register) than it is worth to pass the reference instead of copying the value. This is probably the case for pcl::PointXYZ considering:

#define PCL_ADD_POINT4D \
  EIGEN_ALIGN16 \
  union { \
    float data[4]; \
    struct { \
      float x; \
      float y; \
      float z; \
    }; \
  } ;

...

struct _PointXYZ
{
  PCL_ADD_POINT4D;  // This adds the members x,y,z which can also be accessed using the point (which is float[4])
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
};

struct EIGEN_ALIGN16 PointXYZ : public _PointXYZ

(根据 float [ 4] ,它应该占用16个字节。)

(According to float[4], it should consume 16 bytes.)

在观点上,不值得考虑对<$ c $之类的原始类型进行引用c> bool int 和任何指针(通常应适合机器字的宽度)。

In oppisition, it's not worth to consider a reference for primitive types like bool, int, and any pointer (which usually should fit into "machine word" width).

这篇关于当代码中不存在代码行时如何解决Visual Studio 2010 C ++中的错误C2719的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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