27、很酷的C语言技巧
生活随笔
收集整理的這篇文章主要介紹了
27、很酷的C语言技巧
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文獻【1】中列表了幾個C語言技巧。如
1、通過靜態分配存儲空間來初始化特定索引值的指針數組。
View Code /* Entries may not correspond to actual numbers. Some entries omitted. */ #define EINVAL 1 #define ENOMEM 2 #define EFAULT 3 /* ... */ #define E2BIG 7 #define EBUSY 8 /* ... */ #define ECHILD 12 /* ... */ char *err_strings[] = { [0] = "Success", [EINVAL] = "Invalid argument", [ENOMEM] = "Not enough memory", [EFAULT] = "Bad address", /* ... */ [E2BIG ] = "Argument list too long", [EBUSY ] = "Device or resource busy", /* ... */ [ECHILD] = "No child processes" /* ... */ };?2、初始化結構體中特定的元素。
(C++語言通過使用構造函數實現)
View Code struct point { int x; int y; int z; }; struct point p = {.x = 3, .y = 4, .z = 5};?3、宏列表(不錯,值得學習)。
4、編譯時斷言等。
參考
【1】 http://news.cnblogs.com/n/136894/
總結
以上是生活随笔為你收集整理的27、很酷的C语言技巧的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: applyDimension的用法
- 下一篇: vi 编辑器总结