struct items_with_header { int header_field1; unsigned int length; double array[]; };
Then allocate enough memory and use the struct to access it.
Used it once in a hash-table implementation.
struct items_with_header { int header_field1; unsigned int length; double array[]; };
Then allocate enough memory and use the struct to access it.
Used it once in a hash-table implementation.
typename identifier[];
means three different things, depending on where it appears: As a function argument, it is a pointer that will be accessed like an array. As a variable with automatic storage duration, it is an array whose size will be determined by the right-hand-side of an assignment from a braced initializer list. In the middle of a struct definition, it's illegal. And at the end of a struct definition, it is a flexible array member.
class Bar {};
class Foo {
public:
Foo(const Bar &c) { }
void method() { }
};
int main() {
Foo foo(Bar());
foo.method();
return 0;
}
"foo.method();" doesn't compile because: error: request for member ‘method’ in ‘foo’, which is of non-class type ‘Foo(Bar (*)())’
That's right: "foo" is a declared function that returns instance of Foo and takes one argument - a function that returns instance of Bar :) But when you add additional parentheses in a line above: Foo foo((Bar()));
then "foo" is an instance of Foo created by passing a new instance of Bar to its constructor, which is more like what you'd expect by reading the code, and the code compiles. Fun!https://en.wikipedia.org/wiki/Most_vexing_parse#Uniform_init...
https://github.com/sepeth/python-skiplist/commit/00ae7f94246...
Redis's skiplist is also using the same feature:
https://github.com/antirez/redis/blob/unstable/src/server.h#...