Reputation: 751
options->dict_size = UINT32_C(1) << (uint8_t []){
18, 20, 21, 22, 22, 23, 23, 24, 25, 26 }[level];
http://svn.r-project.org/R/trunk/src/extra/xz/lzma/lzma_encoder_presets.c
#ifndef UINT32_C
# if UINT_MAX != 4294967295U
# error UINT32_C is not defined and unsigned int is not 32-bit.
# endif
# define UINT32_C(n) n ## U
#endif
Compiling this for windows. But getting syntax error
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2337: 'level' : attribute not found
typedef struct {
uint32_t dict_size;
// ...
} lzma_options_lzma;
has anyone tried this before?
Also, I have never seen a code like uint8_t []{...}[level]
;
What does it mean?
Upvotes: 1
Views: 857
Reputation: 279255
const static uint8_t shift_lookup[] = {
18, 20, 21, 22, 22, 23, 23, 24, 25, 26 };
options->dict_size = UINT32_C(1) << shift_lookup[level];
Where shift_lookup
is some name that isn't already used in the code.
(uint8_t []){...}
is a C99 compound literal, it is an unnamed object of array type. MSVC doesn't implement C99. To get the equivalent in C89, you have to give it a name.
(uint8_t []){...}[level]
is the normal indexing operator for arrays, applied to the literal.
For this specific case, where the array happens to be of character type, C89 does in fact already have a kind of literal that will work: string literals.
options->dict_size = UINT32_C(1) << "\x12\x14\x15\x16\x16\x17\x17\x18\x19\x1a"[level];
I don't recommend it, though.
Upvotes: 5
Reputation: 399833
That is a C99 compound literal.
It's defining an array, and then indexing into the array in the same expression. If level
is zero, it will shift by 18 bits, if it's one it will shift 20 bits, and so on.
If you're trying to build this with Visual Studio, that's your problem right there since Visual Studio doesn't support C99.
Fixing it would require refactoring to remove the inline array, and make it a regular array instead.
Upvotes: 4