Created
May 20, 2014 15:43
-
-
Save ryochack/6485a343540121887100 to your computer and use it in GitHub Desktop.
#includeを使ってビルド時にenumのインデックスと配列データの整合性を確保する方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* resource_id, addr, len */ | |
| RESOURCE( E_RSC01, 0x10, 4 ), | |
| RESOURCE( E_RSC02, 0x14, 2 ), | |
| RESOURCE( E_RSC03, 0x16, 2 ), | |
| RESOURCE( E_RSC04, 0x18, 4 ), | |
| RESOURCE( E_RSC05, 0x20, 1 ), | |
| RESOURCE( E_RSC06, 0x21, 1 ), | |
| RESOURCE( E_RSC07, 0x22, 2 ), | |
| RESOURCE( E_RSC08, 0x24, 4 ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct resource_info { | |
| unsigned short addr; | |
| unsigned short len; | |
| }; | |
| #define RESOURCE(id, addr, len) id | |
| enum resource_id { | |
| #include "resource.inc" | |
| }; | |
| #undef RESOURCE | |
| #define RESOURCE(id, addr, len) {addr, len} | |
| struct resource_info rsc_blks[] = { | |
| #include "resource.inc" | |
| }; | |
| #undef RESOURCE | |
| int main(int argc, char **argv) | |
| { | |
| unsigned short addr = rsc_blks[E_RSC08].addr; | |
| unsigned short len = rsc_blks[E_RSC08].len; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment