C的值意外定义更改 [英] Value of C define changes unexpectedly

查看:46
本文介绍了C的值意外定义更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有很多 #define .现在一个奇怪的问题已经解决了.

I have a lot of #define's in my code. Now a weird problem has crept up.

我有这个:

#define _ImmSign    010100

(我正在尝试模拟一个二进制数)

(I'm trying to simulate a binary number)

很明显,我希望这个数字会变成10100.但是当我使用这个数字时,它变成了4160.

Obviously, I expect the number to become 10100. But when I use the number it has changed into 4160.

这是怎么回事?而我该如何阻止呢?

What is happening here? And how do I stop it?

附加

好的,这是由于语言将其解释为八进制.但是,是否有某种聪明的方法可以迫使语言将数字解释为整数?如果现在我想到的话,如果前导0定义八进制,而0x定义十六进制...

Okay, so this is due to the language interpreting this as an octal. Is there some smart way however to force the language to interpret the numbers as integers? If a leading 0 defines octal, and 0x defines hexadecimal now that I think of it...

推荐答案

如果您愿意编写不可移植的代码并使用gcc,则可以使用

If you are willing to write non-portable code and use gcc, you can use the binary constants extension:

#define _ImmSign    0b010100

这篇关于C的值意外定义更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆