应该在堆栈上分配的变量的大小是否有最大限制? [英] Is there a maximum limit to the size of a variable that should be allocated on a stack?
问题描述
我在 C 中声明了一个大小大于 1024 字节的结构变量.在运行 Coverity(静态代码分析器应用程序)时,它会报告此堆栈变量大于 1024 字节,因此会导致错误.我想知道我是否需要担心这个警告?单个堆栈变量的大小真的有最大限制吗?
i declared a struct variable in C of size greater than 1024bytes. On running Coverity (a static code analyzer application) it reports that this stack variable is greater than 1024 bytes and therefore a cause of error. I'd like to know if I need to worry about this warning? Is there really a maximum limit to the size of a single stack variable?
谢谢,车
推荐答案
它试图保护你的问题是堆栈溢出,因为不同的执行路径,在测试中很难找到.主要是因为这个原因——在堆栈上分配大量数据被认为是不好的形式.不过,您只有在嵌入式系统上真正可能遇到真正的问题.
The problem it is trying to protect you from is stack overflow, because of different execution paths, it is very hard to find in testing. Mostly for this reason - it is considered bad form to allocate a large amount of data on the stack. You are only really likely to run into a real problem on an embedded system though.
换句话说,它对它认为堆栈上的过多数据设置了任意限制.
In other words, it sets an arbitrary limit to what it considers too much data on the stack.
这篇关于应该在堆栈上分配的变量的大小是否有最大限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!