If array sizes can only be a constant value than what does
char d_name[...]
mean?
Actually, there is a struct dirent declared in dirent.h file. its declaration is as under:
struct dirent{
....
ino_t d_ino;
char d_name[...];
...
};
It is used to read directory contents one at a time i.e. inode numbers and filenames etc…
I mean what is the max size of such an array and how much space is statically allocated in the memory once such an array is defined? Is such a definition portable?
Assuming it’s from
struct linux_dirent, it’s actually chard_name[]:It’s called a flexible array member, using
mallocyou can allocate more memory to the struct givingd_namea variable size.EDIT
The text the OP is quoting:
With the
...the authors signals the size isn’t fixed per standard. Each implementation must choose a fixed size, for example Linux chooses 256. But it’s not valid code.