Dear gnu:
       Here is code:

#include <vector>
#include <iostream>
#include <cstring>

class segment_fault
{
    std::string str;
    int a;
    float *b = nullptr;
};
int main()
{
    std::vector<segment_fault> segments;
    segment_fault sf;
    memset(&sf,0,sizeof(sf));
    std::cout << "segment's size is: "<< sizeof(segment_fault) <<std::endl;

    //copy this object
    segments.push_back(sf);
    return 0;
}

This code can run on the windows system ,but it failed and cause segment fault 
on the centos 7 (read hat) , the gcc version is 8.3.1-3. The further 
information of gcc is below:


[alvin@localhost example_code]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap 
--enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr 
--mandir=/opt/rh/devtoolset-8/root/usr/share/man 
--infodir=/opt/rh/devtoolset-8/root/usr/share/info 
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared 
--enable-threads=posix --enable-checking=release --enable-multilib 
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions 
--enable-gnu-unique-object --enable-linker-build-id 
--with-gcc-major-version-only --with-linker-hash-style=gnu 
--with-default-libstdcxx-abi=gcc4-compatible --enable-plugin 
--enable-initfini-array 
--with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install
 --disable-libmpx --enable-gnu-indirect-function --with-tune=generic 
--with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)

发送自 Windows 10 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>应用

Reply via email to