添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
It doesn't matter where the const declarations are, C51 refuses to compile it. It seems like it ought to work. In the real deal, I was planning on having groups pointers to arrays in various parts gathered in one location in arrays. But even in this simplified version, it doesn't work. Attempting to do anything like this just results in:

error C247: non-address/-constant initializer What's more, the exact same thing works in GCC with language c and STRICT ANSI and doesn't produce any errors. In fact, I can dereference MC_buf and get the value of an_object.

No, it shouldn't. Initializers of static objects have to be compile-time constants. It comes as a surprise to everyone at some point while learning C, so don't be too upset about it: no, 'const'-qualified variables are not compile-time constants.

What's more, the exact same thing works in GCC with language c and STRICT ANSI and doesn't produce any errors.

Hmm... are sure? I consistently get an error:

c:\temp> gcc -c tt.c tt.c:5: initializer element is not constant Oh! I was completely zoning out on what that error message was saying and reading it wrong. Ha! I feel stupid now.

Thanks for the wake-up.