-
-
Save klange/4c5b674f12e678e7ea070ead2fb0acdd to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Flexible arrays | |
* | |
* Initialize 'foo' as a char array with the contents | |
* of 'file.dat'. 'sizeof foo' is the size of file.dat. | |
*/ | |
char foo[] [[embed("file.dat")]]; | |
/** | |
* Flexible structs | |
* | |
* Same as for arrays, though since sizeof() can't do | |
* what it should here under normal circumstances, don't | |
* expect it to work in this case either... | |
* | |
* Maybe issue a warning if "file.dat" is of insufficient | |
* size to fill required members of 'struct Bar'. | |
* | |
* Struct padding is 1-1, as if 'bar' was set by | |
* reading the file directly into it. | |
*/ | |
struct Bar { | |
size_t size; | |
char stuff[]; | |
}; | |
struct Bar bar [[embed("file.dat")]]; | |
/** | |
* Non-flexible objects: | |
* | |
* Use sizeof(type) bytes from file.dat, but object | |
* remains same size as base type. | |
*/ | |
uint64_t baz [[embed("file.dat")]]; /* sizeof(uint64_t) bytes from file.dat */ | |
char qux[16] [[embed("file.dat")]]; /* (up to?) 16 bytes from file.dat */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment