#定义变量类型 [英] Type of #define variables

查看:78
本文介绍了#定义变量类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有:

#define MAXLINE    5000

是什么类型MAXLINE理解为?我应该假设它是一个 INT ?我能以某种方式测试它?

What type is MAXLINE understood to be? Should I assume it is an int? Can I test it somehow?

在一般情况下,一个人如何能确定的#define 编辑变量的类型?

In general, how can one determine the type of #defineed variable?

推荐答案

它没有类型。这是一个简单的文本替换。该文本将5000到位的地方MAXLINE显示为令牌被丢弃。

It has no type. It is a simple text substitution. The text 5000 will be dropped in place wherever MAXLINE appears as a token.

例如:

int a = MAXLINE;

将投入价值5000 A

char *MAXLINE2 = "MAXLINE";

不会导致

char *50002 = "5000";

所以,如果你想类型检查,宏的不是要走的路。您将要声明静态常量来代替,这样的类型检查是由编译器完成。

So, if you want type-checking, macro's are not the way to go. You will want to declare static constants instead, that way type-checking is done by the compiler.

有关的静态常量的#define ,有很多来源,包括这样的问题:静态,定义和常量用C

For information on the differences between static, const, and #define, there are many sources, including this question: static, define, and const in C

这篇关于#定义变量类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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