Invalid use of 'void'

Niklas Gürtler profclonk@gmail.com
Mon May 18 15:03:56 GMT 2020


On 5/18/20 12:30 PM, Игорь Горлов wrote:
> This program is not compatible with the C++17 standard. However, we can compile it with -std=gnu++17 (C++17 with GNU extensions), because one of that extensions permits calculations on void pointers.

It appears the extension is only for C, not for C++:
https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Pointer-Arith.html#Pointer-Arith

Also, the C and C++ standards forbid subtracting pointers that do not
point into the same array, so subtracting the results of two distinct
'malloc' calls is undefined behaviour.

See e.g.
https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array



More information about the Gcc-help mailing list