定义一个大小大于 unsigned int 限制的大数组
我需要静态定义一个大小为 12884901888 的数组(在 *.h 中)。
unsigned char sram[12884901888]; //All of my code is C.
上面的声明给出了错误并且不起作用。
因为数组声明中使用的常量是unsigned int。 但我需要使用的常量(12884901888)大于 unsigned int 限制。
我如何定义上面的数组,大小为 12884901888 ?
谢谢。
-AD
P.S. 我知道很多人会说,优化那个巨大的数组大小,但由于某些特定于我的情况的原因,我需要使用相同的数组大小。
I need to define an array statically (in a *.h) file of size 12884901888 like.
unsigned char sram[12884901888]; //All of my code is C.
Above declaration gives error and does not work.
Because constants used in array declarations are unsigned int. But the constant i need to use (12884901888) is larger than the unsigned int limit.
How can i define the array as above, of size 12884901888 ?
Thank you.
-AD
P.S. I know many will say, optimize on that humongous array size, but i need to use same for some reason specific to my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使数组维度为 unsigned long long。
Make the array dimension an unsigned long long.
这是用于嵌入式微控制器吗? 您通常可以摆脱类似的情况:
除非您的编译器实现了边界检查,否则数组大小并不重要。 无论如何,您都不希望编译器尝试保留 12884901888 字节,因为链接将会失败。
Is this for an embedded microcontroller? You can often get away with something like:
Unless your compiler implements bounds checking, the array size does not matter. In any case you do not want the compiler to attempt to reserve 12884901888 bytes, because linking will fail.
将 12884901888 转换为十六进制给出:0x3-0000-0000
(我将每组16位分开)
也就是说,这个无符号字节数组需要3乘以4 Gig
编译器应该生成 34 位地址指针才能工作,
我同意 finnw,您不需要告诉编译器数组的大小。 如果您指定了大小,您将获得该模块的一个大 OBJ 文件以及最终可执行文件的类似大 ELF/EXE。
Converting 12884901888 to hexadecimal gives : 0x3-0000-0000
(I separated each group of 16 bits)
In other words, this array of unsigned bytes needs 3 times 4 Gig
The compiler is supposed to generate 34 bits address pointer for this to work
I agree with finnw, you don't need to tell the compiler the size of the array. If you do specify the size, you will get a large OBJ file for the module and similarly large ELF/EXE for the final executable.