本文介绍了C编译器中的主列阵存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

是否有任何C编译器具有以列主要顺序而不是标准行主顺序存储数组的扩展名?

Are there any C compilers that have extensions to store an array in column-major order instead of the standard row-major order?

推荐答案

简短的回答是否。

长回答是以列为主的顺序存储数组会破坏数组索引之间的一一对应关系操作和指针算术,以及将N维数组切成N-1维数组的方式。

Long answer is that storing an array in column-major order would break the one-to-one correspondence between array index operations and pointer arithmetics, and the way an N-dimension array is sliced into N-1 dimension arrays.

考虑一个以列为主的顺序存储的10x20数组。这意味着相邻列中的单元将在存储器中彼此相邻。另一方面,将指向i,j上的数组元素的指针转换为元素指针必须工作如下:

Consider a 10x20 array stored in column-major order. This means that cells in adjacent columns would be next to each other in memory. On the other hand, converting a pointer to array element at i, j to an element pointer must work like this:

int *p=&a[1][5];
int *q=&a[1][6];
p++;

标准要求p等于q,因为两个指针指向相邻的元素。如果数组a以列为主的顺序存储,这将是不可能的。

The standard requires that p is equal q, because the two pointers point to adjacent elements. This would not be possible if array a were stored in column-major order.

在C中,你必须编写自己的一组函数来处理这些数组。但是,如果使用C ++编写代码,则可以选择实现自己的多维数组,并重载括号操作符(),以列为主的顺序工作。

In C you would have to write your own set of functions to work with such arrays. If you code in C++, however, you would have an option to implement your own multi-dimension array, and overload the parentheses operator () to work in a column-major order.

这篇关于C编译器中的主列阵存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:31