什么是C中的bogus_type
我一直在浏览libgcc中定义的一些类型。 它们显然都映射到名为bogus_type
的相同类型。 我找不到它的定义。
#define SItype bogus_type #define USItype bogus_type #define DItype bogus_type #define UDItype bogus_type #define SFtype bogus_type #define DFtype bogus_type
这种类型映射到什么? 它甚至是一个有效的类型或类似NULL
东西?
这是使用这种“类型” 的另一个例子 。
/* Make sure that we don't accidentally use any normal C language built-in type names in the first part of this file. Instead we want to use *only* the type names defined above. The following macro definitions insure that if we *do* accidentally use some normal C language built-in type name, we will get a syntax error. */ #define char bogus_type #define short bogus_type #define int bogus_type #define long bogus_type #define unsigned bogus_type #define float bogus_type #define double bogus_type
那就是说, 它不是一种类型。 在程序的某些位置强制使用某些类型是一种合法的代码破坏者 。 如果它触发,编译应该因语法错误而失败,因为bogus_type
不存在。
它不是语言中任何“不为人知的”部分,它只是巧妙地使用C预处理器。
它放在一些代码之前, 不应该在以后偶然使用这些类型之一。 因此,如果它正在使用其中之一,编译器将抛出错误,因为没有这样的bogus_type
类型。
由于define
只是在编译阶段之前发生的文本替换,只要没有人会使用定义的类型,就不会替换bogus_type
,也不会发生任何事情。 如果有人将使用这些类型,它们将被替换为bogus_type
,实际上没有在任何地方定义,这将使编译失败。
所以基本上bogus_type
只是一个拉比,用于在特定类型中使用时强制失败构建。 为此,它可能是:
#define SItype you_are_using_a_type_you_should_not_be_using!