如何修复错误 c2118:负下标
再次将 32 位应用程序移植到 64 位。我在下面提到的 C_ASSERT 语句中收到负下标错误。
C_ASSERT (sizeof(somestruct) == some#define);
我还阅读了 http://support.microsoft .com/kb/68475 文章,但不确定我是否知道在这种情况下如何解决它。
感谢帮助。
提前致谢。
Again, porting 32-bit app to 64-bit. I get the negative subscript error on the C_ASSERT statement mentioned below..
C_ASSERT (sizeof(somestruct) == some#define);
I also read the http://support.microsoft.com/kb/68475 article but not sure if I know how to fix it in this case.
Help is appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜测
C_ASSERT
宏的定义如下:这是一个编译时断言:如果编译时表达式
x
为 true,则它会扩展为某个内容就像将类型名称
C_ASSERT_1
声明为类型char[1]
的别名(1 个char
的数组)。相反,如果表达式 x 为 false,则它会扩展为编译器错误,因为不能使用负大小的数组类型。
因此,您的问题是表达式
sizeof(somestruct) == some#define
为 false,即somestruct
的大小不是您的代码所期望的。您需要解决此问题 - 更改somestruct
的大小,或更改some#define
的值,确保这不会破坏任何内容。I'm guessing the
C_ASSERT
macro is defined something like this:This is a compile-time assertion: if the compile-time expression
x
is true, then this expands to something likewhich declares the typename
C_ASSERT_1
to be an alias for the typechar[1]
(array of 1char
). Converely, if the expressionx
is false, it expands towhich is a compiler error, since you can't have an array type of negative size.
Hence, your problem is that the expression
sizeof(somestruct) == some#define
is false, i.e. the size ofsomestruct
is NOT what your code is expecting. You need to fix this -- either change the size ofsomestruct
, or change the value ofsome#define
, making sure that this won't break anything.