局部静态变量是嵌入式编译器提供的吗?

发布于 2024-08-21 03:32:39 字数 164 浏览 9 评论 0原文

我正在研究 ac lib,如果也能在嵌入式系统上工作的话那就太好了 但我对嵌入式开发不是很深入,所以我的问题

是大多数嵌入式编译器能够处理局部静态变量 - 然后我会在进一步的开发中假设这一点 或者 是否有一个 #define,我可以使用它作为 #ifdef 创建全局变量,以防

万一

im working on a c lib which would be nice to also work on embedded systems
but im not very deep into embedded development so my question

are most embedded compilers able to cope with local static variables - which i would then just assume in further development
OR
is there a #define which i can use for a #ifdef to create a global variable in case of

thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

御弟哥哥 2024-08-28 03:32:39

它们应该如此,因为局部静态变量是 C 标准的一部分。

当然,没有什么可以阻止他们创建一种不具备所有功能的类 C 语言。但由于这将是非标准的,因此识别缺少功能的方法也将是非标准的。

They should, as local static variables are part of the C standard.

Of course, there is nothing preventing them from creating a C-like language that does not have all the features. But since that would be non-standard, then the way to identify that a feature is lacking would be non-standard as well.

寻找我们的幸福 2024-08-28 03:32:39

由于静态变量是标准的一部分,因此您应该是安全的。

支持的问题可能不是你的编译器(其中大多数都能很好地处理标准)发现的,而是你必须设置运行时环境的任何代码发现的。确保在加载代码时正确解压可执行文件的可执行文件、只读数据、读写数据和零初始化部分,然后再跳转到 C 代码。

Since static variables are part of the standard, you should be safe.

The problem with support is probably not to be found with your compiler (most of which handle the standard pretty well), but with whatever code you have to set up your runtime environment. Make sure that when you're loading the code that you properly unpack the executable, read-only data, read-write data, and zero-init sections of the executable before jumping into the C code.

最笨的告白 2024-08-28 03:32:39

局部静态变量是 C 标准的一部分,所以是的。

\pedantic{

如果您的代码组织良好,对于不同的子系统具有单独的文件(编译单元),那么您可能会更好地使用具有文件范围的静态变量。这将使将使用它的代码更容易地分解为单独的函数。如果使用变量的代码很复杂,这将允许您将其拆分为更小的静态函数,这些函数更容易阅读、理解和调试。

}

Local static variables are part of th C standard, so yes.

\pedantic{

If your code is well organized, with separate files (compilation units) for different subsystems, you might do better to have a static variable with file scope. This will make it easier to factor the code that uses it into separate functions. If the code that uses the variable is complicated, this will permit you to split it into smaller static functions, which are easier to read, understand and debug.

}

倾城花音 2024-08-28 03:32:39

是的。一旦编译器完成对源代码的咀嚼,局部静态实际上与全局没有太大区别。我可以想到一些奇特的处理器,其中全局变量会成为一个问题,但我怀疑您会遇到很多。

嵌入式处理器上的全局变量真正有趣的地方在于,您通常可以选择让编译器将它们分配到 ROM、EEPROM 等中。

Yes. local statics are really not much different than globals once the compiler is done chewing on your source code. I could think up exotic processors where globals would be an issue, but I doubt you will encounter many.

The truly interesting thing about globals on embedded processors is that you often have the option of having the compiler allocate them in ROM, EEPROMs, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文