的C隐藏功能 [英] Hidden features of C

查看:113
本文介绍了的C隐藏功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有所有的C编译器实现背后的标准,因此,应该没有隐藏的功能。尽管如此,我相信所有的C开发人员隐藏/秘密技巧,他们使用的所有时间。

I know there is a standard behind all C compiler implementations, so there should be no hidden features. Despite that, I am sure all C developers have hidden/secret tricks they use all the time.

推荐答案

多字符常量:

int x = 'ABCD';

这集 X 0x41424344 (或 0x44434241 取决于体系结构)。

This sets x to 0x41424344 (or 0x44434241, depending on architecture).

编辑::该技术是不可移植的,特别是如果你序列化INT。
然而,这是非常有用的创造自我记录枚举。例如。

This technique is not portable, especially if you serialize the int. However, it can be extremely useful to create self-documenting enums. e.g.

enum state {
    stopped = 'STOP',
    running = 'RUN!',
    waiting = 'WAIT',
};

这使得它更简单,如果你正在寻找一个原始内存转储和需要确定一个枚举值,而不必来关注一下吧。

This makes it much simpler if you're looking at a raw memory dump and need to determine the value of an enum without having to look it up.

这篇关于的C隐藏功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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