xcode #定义负数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15870140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:09:12  来源:igfitidea点击:

#define negative numbers?

iosobjective-cxcodec-preprocessor

提问by David

Simple question, but I cannot seem to find the answer. Is it okay to use #defineto define a negative number, as in:

简单的问题,但我似乎无法找到答案。是否可以使用#define定义负数,如:

#define kGravity -9.8

XCode is changing the 9.8 to the color of my numbers I have set (purple), but the -is being shown as the same color as the define statement (orange).

XCode 正在将 9.8 更改为我设置的数字的颜色(紫色),但-显示为与定义语句(橙色)相同的颜色。

Is this legal? Will it compile?

这是合法的吗?它会编译吗?

回答by Paul Armstrong

Did you try it? It should work fine.

你试了吗?它应该可以正常工作。

However, I would encourage you to not use pre-processor macros, but instead use real constants.

但是,我鼓励您不要使用预处理器宏,而是使用实常数。

static const float kGravity = -9.8f;

Preprocessor directives are a bit frowned upon, in general. Here's some more info on the subject: #define vs const in Objective-C

一般来说,预处理器指令有点不受欢迎。这里有一些关于这个主题的更多信息:#define vs const in Objective-C

回答by dasblinkenlight

It is absolutely legal to define negative constants with #define. What you discovered is most likely a bug in Xcode's code coloring, which will probably be fixed in one of the future revisions.

用 定义负常数是绝对合法的#define。您发现的很可能是 Xcode 代码着色中的一个错误,该错误可能会在未来的某个修订版中得到修复。