宏以测试整数类型是否带符号 [英] Macro to test whether an integer type is signed or unsigned

查看:102
本文介绍了宏以测试整数类型是否带符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你会怎么写(在C / C ++),如果一个整数类型(作为参数)带符号,它测试的宏?

      #定义is_this_type_signed(my_type)...


解决方案

如果你想要的是一个简单的宏,这应该做的伎俩:

 的#define is_type_signed(my_type)(((my_type)-1)℃下)

How would you write (in C/C++) a macro which tests if an integer type (given as a parameter) is signed or unsigned?


      #define is_this_type_signed (my_type) ...

解决方案

If what you want is a simple macro, this should do the trick:

#define is_type_signed(my_type) (((my_type)-1) < 0)

这篇关于宏以测试整数类型是否带符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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