Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Eigen中内存是如何布局的?_C++_Arguments_Eigen - Fatal编程技术网

C++ 在Eigen中内存是如何布局的?

C++ 在Eigen中内存是如何布局的?,c++,arguments,eigen,C++,Arguments,Eigen,我编写了这个小解析器,它从文本文件中读取一些数字 data.resize(7,datapoints); //Eigen::Matrix<float,7,-1> & data dst = data.data(); while( fgets(buf,255,fp) != 0 && i/7 < datapoints) { int n = sscanf(buf,"%f \t%f \t%f \t%f \t%f \

我编写了这个小解析器,它从文本文件中读取一些数字

    data.resize(7,datapoints); //Eigen::Matrix<float,7,-1> & data
    dst = data.data();

    while( fgets(buf,255,fp) != 0 && i/7 < datapoints)
    {

        int n = sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+i++, dst+i++,dst+i++,dst+i++,dst+i++,dst+i++,dst+i++);
            i = i - 7 * (n<=0);
    }
    fclose(fp);
    return !(datapoints == i/7);
数据。第(3)列为

和数据。第(4)列为

我看不出它为什么将数据水平翻转的逻辑?

你确定吗

int i=0;
sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+i++, dst+i++,dst+i++,dst+i++,dst+i++,dst+i++,dst+i++);
等于:

sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+0,dst+1,dst+2,dst+3,dst+4,dst+5,dst+6 );

我认为变量列表arg在本例中得到了重新计算,而@Christian Rau comment通常未定义计算顺序。通常,了解副作用顺序不是一个好主意

为了说明问题:

#include <cstdio>

void f(int i, int j, int k)
{
  printf("i = %d\tj = %d\tk = %d\n", i, j, k);
}

int main()
{
  int i=0;
  f(i++, i++, i++);
}

函数调用中
i++
调用的执行顺序完全由实现定义(即任意)。

是的,开始时i=0。“我认为变量列表参数得到了重新计算”-不,不是。它是按未定义的顺序计算的,这就是为什么他的代码最终可以产生任何可能的输出。但是,由于这个未定义的求值顺序,您的代码行是正确的。什么?你是说第一个%f没有映射到格式字符串后的第一个参数?@s093294:没有,他是说,函数参数的计算顺序没有确定。它可能会导致如下任何行为:
sscanf(“…”,dst+3,dst+1,dst+4,dst+2,dst+0)
或类似于您的情况,以相反的顺序。@s093294第一个
%
当然会映射到第一个函数参数,但这并不一定意味着这些函数参数是按此顺序计算的。想象一下,您的编译器将所有这些函数参数计算成临时变量,而这是以完全未定义的顺序进行的。然后,它使用这些计算结果调用函数。您将不得不展开
执行std::cout
std::cout[的]时间[是16分钟前]。问题局部化,前提中断,
sscanf
调用中断。eigen可能在初始调试期间被抽象出来,以揭示这个bug。嗯,我猜你每天都会学到新东西。我希望您能给出一条评论,说明为什么不按解析顺序对其进行计算。请询问google或在此处查看:我是否应该理解为格式字符串中的第一个%f可以复制到末尾的任何参数中?或者只是每个参数位置上的代码可以按任何顺序计算?各种
i++
调用的顺序是未定义的。这意味着,
fscanf
调用的字段可以按任何顺序洗牌。
int i=0;
sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+i++, dst+i++,dst+i++,dst+i++,dst+i++,dst+i++,dst+i++);
sscanf(buf,"%f \t%f \t%f \t%f \t%f \t%f \t%f",dst+0,dst+1,dst+2,dst+3,dst+4,dst+5,dst+6 );
#include <cstdio>

void f(int i, int j, int k)
{
  printf("i = %d\tj = %d\tk = %d\n", i, j, k);
}

int main()
{
  int i=0;
  f(i++, i++, i++);
}
i = 2   j = 1   k = 0