segment fault
Jonathan Wakely
jwakely.gcc@gmail.com
Tue Apr 28 08:45:10 GMT 2020
On Tue, 28 Apr 2020 at 07:07, luo alvin <alvinlmf@hotmail.com> wrote:
>
> Thank you very much for replying me. I also think it not bug,because I test this code in the lower version(lower than 8.3.1-3) of gcc,all cause segment fault. The funny thing is that if you run this code higher than gcc version(8.3.1-4)(actually I only test code in the version 8.3.1-4),the result is fine(doesn’t lead to segment fault).
Your program has undefined behaviour. That means anything can happen.
>furthermore, I found that the value of sizeof(std::string) is different between gcc versions. Value in version 8.3.1-3 is 8 ,and 32 in version 8.3.1-4.
That is not caused by the GCC version, it's caused by a different
default for the _GLIBCXX_USE_CXX11_ABI macro. When the default is 0
sizeof(std::string) == sizeof(char*) but when the default is 1
sizeof(string) is larger.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
for more information about the macro.
More information about the Gcc-help
mailing list