开发者

define - constant or literal Objective-C

We have the following code (in the .h. or .m file of Objective-C app)

#define SQUARE_SIZE 28
#define APP_DELEGATE [[UIApplication sharedApplication] appDelegate]

are both of them constants or literals ?

What is t开发者_运维技巧heir proper name? And it they are literals as I suspect, why most call them constants :)?


They're neither, they're macros.

A constant would look like this:

const int square_size = 28;

The difference between a macro and a constant here is that the constant has a type while a macro is simply some text fragment that gets inserted at the place where it's mentioned before the compiler is parsing the source code.

And a literal is something like 28 or @"This is a string", that is a value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜