为什么我不能在preprocessor条件sizeof的使用? [英] Why can't I use sizeof in a preprocessor condition?

查看:185
本文介绍了为什么我不能在preprocessor条件sizeof的使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,sizeof的是运营商,它在编译时被评估为整型常量。
但它似乎它不能像在#if preprocessor指令中使用

I understand that sizeof is an operator, which is evaluated at compile time to an integer constant. But it seem it can not be used in the #if preprocessor directive like:

#if 4 == sizeof(int)
    typedef int Int32;
#endif

(cygwin的-GCC 3.4.4以及Visual C ++ 6.0编译报告错误)

(cygwin-gcc 3.4.4 as well as Visual C++ 6.0 report compile errors)

为什么这种用法不允许?

Why is such usage not allowed?

推荐答案

由于的sizeof 在编译时计算,同时指令之前编辑评价的 ,那确实该部分不是编译器,所以它不会明白什么的sizeof 表示。

Because sizeof is evaluated at compilation time while directives are evaluated before compilation, and the part that does that is not the compiler, so it won't understand what sizeof means.

这篇关于为什么我不能在preprocessor条件sizeof的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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