... or, in other words, is it safe to initialize system structures like this:
struct timespec ts[] = { {0, UTIME_OMIT}, {0, UTIME_OMIT} };
...
int r = utimensat(0, subPath.c_str(), ts, 0);
?
... or, in other words, is it safe to initialize system structures like this:
struct timespec ts[] = { {0, UTIME_OMIT}, {0, UTIME_OMIT} };
...
int r = utimensat(0, subPath.c_str(), ts, 0);
?
Copyright © 2021 Jogjafile Inc.
If you are relying only on POSIX, then no, it is not guaranteed that the initialization you present will have the effect you want. This is the extent of what it has to say about the definition of that structure type:
It does not specify the relative order of those two members, nor does it specify that they be the first or only members, therefore it is not safe for your initializers to rely on member order.
However, POSIX specifies C99 and incorporates it by reference, so you can use designated initializers to achieve about what you want:
Or, per @Storyteller's comment, C++20 catches up to C in that area if you want to write in that language. I confess, however, that until I looked more closely at the question's tags, I assumed C based on the use of this general style of initialization at all.