数组索引开始在一些不为0 [英] Array indexing starting at a number not 0

查看:291
本文介绍了数组索引开始在一些不为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能指数不为零......即在开始的数组。
你有发言权100起一个数组[35],35元的,现在我要指标,所以这些数字将是[100],A [101],... A [134],这可能吗?

Is it possible to start an array at an index not zero...I.E. you have an array a[35], of 35 elements, now I want to index at say starting 100, so the numbers would be a[100], a[101], ... a[134], is that possible?

我试图产生记忆图董事会和我有一个数组称为SRAM [10000]和另一个叫BRAM [5000]例如,但在记忆的可见他们是连续,IE BRAM开始SRAM之后,所以因此如果我尝试指向内存位置11000我会读它看到,它的10000然后将它传递给BRAM。

I'm attempting to generate a "memory map" for a board and I'll have one array called SRAM[10000] and another called BRAM[5000] for example, but in the "memory" visiblity they're contiguous, I.E. BRAM starts right after SRAM, so therefore if I try to point to memory location 11000 I would read it see that it's over 10000 then pass it to bram.

在输入这个,我意识到我,我可以想,然后从数量减去10K和传递到BRAM,但对于参数的缘故,这可能路过11000到BRAM指数?

While typing this I realized I could I suppose then subtract the 10K from the number and pass that into BRAM, but for the sake of argument, is this possible to index passing 11000 to BRAM?

感谢您的任何帮助。

更新来修复一个[34]对[134]

Updated to fix the a[34] to a[134]

更新了其他信息:
在实际的架构我将实施,有可能/可能是SRAM和BRA​​M之间的差距因此,例如地址11008可能不是在内存映射可见,从而书写一个巨大的阵列充分的内存然后选择分区,它将的工作,但我还是要做的逻辑判断,如果是SRAM和BRA​​M的范围内。这正是我想避免在首位。

Updated for additional information: In the actual architecture I will be implementing, there can/may be a gap between the sram and bram so for example the address 11008 might not be visible in the memory map, thus writing a giant array full of memory then "partitioning" it will work, but I'll still have to do logic to determine if it's within the ranges of "sram and bram". Which is what I wanted to avoid in the first place.

推荐答案

<块引用>是否有可能指数不为零......即在开始的数组。你有发言权100起一个数组[35],35元的,现在我要指标,所以这些数字将是[100],A [101],... A [134],这可能吗?

不,你不能这样做在C数组总是从零开始。在C ++中,你可以写自己的类,比如 OffsetArray 和重载 [] 运算符来访问底层数组,而减去从索引的偏移。

No, you cannot do this in C. Arrays always start at zero. In C++, you could write your own class, say OffsetArray and overload the [] operator to access the underlying array while subtracting an offset from the index.

<块引用>我试图产生记忆图董事会和我有一个数组称为SRAM [10000]和另一个叫BRAM [5000]例如,而是在记忆的可见他们重新连片,IE BRAM开始SRAM之后,所以因此如果我尝试指向内存位置11000我会读它看到,它的10000然后将它传递给BRAM。

您可以尝试这样的事:

char memory[150000];
char *sram = &memory[0];
char *bram = &memory[100000];

现在,当您访问 SRAM [110000] 你要访问的东西的,在 BRAM

Now, when you access sram[110000] you'll be accessing something that's "in bram"

这篇关于数组索引开始在一些不为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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