4 ms·
I fail to see your point here. sgl_baseof uses offsetof with a valid struct type and a valid field name, so where is the UB? Unless you feed it an invalid poin
by sifoobar 8y ago
I fail to see your point here.
sgl_baseof uses offsetof with a valid struct type and a valid field name, so where is the UB? Unless you feed it an invalid pointer, but then all bets are off.
- sifoobar 8y agoSorry, still not getting it. If an implementation provides offsetof and it doesn't work, that implementation would go out of fashion in a heart beat. Where is the practical use of this information? How is this even an argument?
- potiuper 8y agoThe use of the Offsetof macro in a program will cause undefined behavior when compiled with GCC or Clang and they are still "in fashion" as far as I am aware. The practical use of this information is to prevent the occurrence of undefined behavior by knowing not to use offsetof for example with GCC and instead use __builtin_offsetof in the specific case of GCC. The argument appears to be that you are claiming that what sgl_baseof does is not undefined behavior and I am claiming that it is not possible to infer that without specifying the implementation of the offsetof macro.
- potiuper 8y agohttps://en.wikipedia.org/wiki/Offsetof https://en.wikipedia.org/wiki/Offsetof repeats what is said the SO link and might be helpful? The occurrence of the UB is not dependent on the parameters that sgl_baseof is called with. The UB may occur solely based on the compiler and standard library implementation. If the UB does occur based on those two and offsetof is not redefined somewhere, then the UB occurs anywhere offsetof is used.