简体   繁体   English

警告:数组元素超过 100

[英]warning:array elements are more than 100

I have a piece of code declaring an array.我有一段代码声明一个数组。

#define MAX_ELEMENT 150
Struct_arr  arr_elem[MAX_ELEMENT];

Here Struct_arr is a structure.这里Struct_arr是一个结构。 On compilation i am getting the warning for this later line as:在编译时,我收到后一行的警告:

warning:array elements are more than 100

could someone please help me about this?有人可以帮我解决这个问题吗?

regards, vivG问候, vivG

That's almost certainly the result of a #warning directive in the code somewhere.这几乎可以肯定是代码中某处的#warning指令的结果。 C++ itself does not limit you to 99 array elements, this will be an artificial limit introduced for some reason. C++ 本身并不限制您使用 99 个数组元素,这将是出于某种原因引入的人为限制。

My advice would be to search for that message and see if there's any comments close by which explain why that's a problem.我的建议是搜索该消息,看看附近是否有任何评论可以解释为什么会出现问题。 Something like:就像是:

fgrep 'array has more than' *.c *.cpp *.h *.hpp

in as UNIX-like operating system would be a good starting point.在类 UNIX 操作系统中将是一个很好的起点。

The warnings says that you're trying to allocate a big array on the stack.警告说您正在尝试在堆栈上分配一个大数组。 On typical linux system, the stack has 8Mb, so it can be quite easy to reach that limit (causing a segfault).在典型的 linux 系统上,堆栈有 8Mb,因此很容易达到该限制(导致段错误)。 This is why you have this warning.这就是您收到此警告的原因。

As you tagged your question as C++, please notice that it's not very common to use C-style array in C++.当您将问题标记为 C++ 时,请注意在 C++ 中使用 C 样式数组并不常见。 You would rather use an你宁愿使用

std::vector<Struct_arr> arr_elem(150);

This allocates a vector of 150 elements, but it can be dynamicaly resized, so if you allocated such a big array "just in case", then a std::vector is even more the way to go.这分配了一个包含 150 个元素的向量,但它可以动态调整大小,因此如果您“以防万一”分配了这么大的数组,那么 std::vector 甚至更适合 go。

Last thing, just use plain old constants instead of macros, there is really no benefit from using them in this particular situation.最后一件事,只使用普通的旧常量而不是宏,在这种特殊情况下使用它们确实没有任何好处。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态数组崩溃超过8个元素 - Dynamic array crashed for more than 8 elements 数组中出现大于 size/2 的元素 - Elements in an array occurring more than size/2 在数组中使用多于分配的元素具有未定义的行为 - Using more elements in array than allocated has undefined behavior 在N个元素的数组中找到“ P”个元素的最小和,以便在一起选择的“ k”个连续元素不超过 - Find the minimum sum of 'P' elements in an array of N elements such that no more than 'k' consecutive elements are selected together 为什么我初始化数组容器的元素大于数组大小时没有出错? - Why I do not get errors when I initialize an array container with more elements than the size of the array? 有没有办法一次操作数组的所有元素/一次操作多个变量? - Is there a way to Manipulate all elements of an array at once/more than one variable at once? 如何在每个块的元素多于线程的数组上执行并行扫描? - How is a parallel scan performed on an array with more elements than threads per block? 与std :: array相比,vector是否使用更多的取消引用来访问元素? - Does a vector use one more dereference to access elements than std::array? C / C ++压缩库能够处理数组中超过32位的元素 - Compression library for C / C++ able to deal with more than 32 bit elements in the array C++:成对访问值比访问数组元素高效得多吗? - C++: Is accessing values in pairs so much more efficient than accessing array elements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM