Reading some kernel code.
I cannot get my head on what this line is meaning
*(void **) &(int[2]){0,PAGE_SIZE};
and more, what does this means
{0,PAGE_SIZE}
To me it doesn't look like a function with that comma.
What could be going on with this code ? I don't understand the indirections here.
Is it a function or a cast ? What does the bracket part means ? Seems so convoluted to me but definitely has a meaning.
Void functions are stand-alone statements In computer programming, when void is used as a function return type, it indicates that the function does not return a value. When void appears in a pointer declaration, it specifies that the pointer is universal.
The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.
void (C++) When used in the declaration of a pointer, void specifies that the pointer is "universal." If a pointer's type is void* , the pointer can point to any variable that's not declared with the const or volatile keyword. A void* pointer can't be dereferenced unless it's cast to another type.
Not only is it OK to free() a void * value, by definition, all free() ever sees is a void * , so technically, everything freed in C is void * :-) @Daniel - If you ask me, it should be struct foo *p = malloc(sizeof *p)); but what do I know?
(int[2]) { 0, PAGE_SIZE }
is an expression (called compound literal) whose value is an array of two int
s. The address of this array is taken, casted to void **
, and dereferenced.
The net result is a reinterpretation of the array contents as a pointer to void.
Note that you can take the address of a compound literal, as they are lvalues. See eg. this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With