Segmentation fault on vectors.

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5

67 Replies - 1957 Views - Last Post: 20 August 2019 - 03:48 PM Rate Topic: -----

#31 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 07 July 2019 - 10:20 PM

Why would the compiler(g++) have a problem with me returning a int? Isn't size_t just a unsigned int? That seems to have fixed it.

This post has been edited by Xrey274: 07 July 2019 - 10:22 PM

Was This Post Helpful? 0
  • +
  • -

#32 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,935
  • Joined: 08-August 08

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 05:01 AM

A vector can hold more items than int can index. Are you sure that fixed it, or was it getting rid of std::vector<int>& doSmth()?
Was This Post Helpful? 0
  • +
  • -

#33 jimblumberg   User is offline

  • member icon

Reputation: 5761
  • View blog
  • Posts: 17,640
  • Joined: 25-December 09

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 05:22 AM

Quote

Isn't size_t just a unsigned int?

Not necessarily, a size_t can be almost any unsigned type. On many systems it happens to be the same as an unsigned int, but it could be an unsigned long, unsigned long long, unsigned short depending on the implementation.

Jim
Was This Post Helpful? 0
  • +
  • -

#34 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 12:22 PM

Ok I am really confused - at first I removed doSmth function and changed the return type of getSize from int to size_t. That fixed. Then you mentioned the possibility of it being from doSmth() so I added it back, but left getSize to return size_t, code::blocks once again crashed. So I removed doSmth again thinking it was the cause, but now it's crashing again with the very same code as the beggining(no doSmth, size_t getSize).

If I have to be more specific - code::blocks doesn't crash by itself, but rather after i hit build & run it starts compiling and never stops(usually takes 1-2 seconds) so when I try to close it that's when it freezes and crashes.

This post has been edited by Xrey274: 08 July 2019 - 12:23 PM

Was This Post Helpful? 0
  • +
  • -

#35 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 12:45 PM

What version of Code::Blocks are you using? What compiler toolchain are you using? What OS are you on? Have you tried disabling your anti-virus?
Was This Post Helpful? 0
  • +
  • -

#36 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 01:02 PM

Code blocks 17.12, g++, Solus KDE, no anti-virus installed on my system.
Was This Post Helpful? 0
  • +
  • -

#37 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 02:34 PM

If I recall correctly, Code::Blocks has something like a build output window. Are there any messages printed out on the window before it hangs?
Was This Post Helpful? 0
  • +
  • -

#38 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 02:48 PM

Perhaps you are talking about the Build Log? All it outputs is the terminal command used to compile the code. Nothing out of the ordinary.

"g++ -c /home/xrey274/test.cpp -o /home/xrey274/test.o
g++ -o /home/xrey274/test /home/xrey274/test.o"
Was This Post Helpful? 0
  • +
  • -

#39 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 03:29 PM

Can you try turning on verbose mode? I believe it is a -v compiler switch.
Was This Post Helpful? 0
  • +
  • -

#40 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,935
  • Joined: 08-August 08

Re: Segmentation fault on vectors.

Posted 08 July 2019 - 07:51 PM

View Postjimblumberg, on 08 July 2019 - 07:22 AM, said:

Not necessarily, a size_t can be almost any unsigned type. On many systems it happens to be the same as an unsigned int, but it could be an unsigned long, unsigned long long, unsigned short depending on the implementation.

size_t depends on the system and the type. In Xcode, it's unsigned long for vectors: 8 bytes. For int, it's 4 bytes.
Was This Post Helpful? 0
  • +
  • -

#41 jimblumberg   User is offline

  • member icon

Reputation: 5761
  • View blog
  • Posts: 17,640
  • Joined: 25-December 09

Re: Segmentation fault on vectors.

Posted 09 July 2019 - 05:37 AM

Quote

size_t depends on the system and the type. In Xcode, it's unsigned long for vectors: 8 bytes. For int, it's 4 bytes.

What does an int have to do with a size_t? An int and a size_t are different types so differences in "sizes" is understandable.

A size_t is an implementation defined unsigned type. On many systems, especially 64 bit operating systems, it is quite often a typedef of an unsigned long. However on many 32 bit operating systems it is usually a typedef of an unsigned int. But remember that the underlying type of size_t is an implementation detail.

Jim
Was This Post Helpful? 0
  • +
  • -

#42 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3825
  • View blog
  • Posts: 13,935
  • Joined: 08-August 08

Re: Segmentation fault on vectors.

Posted 09 July 2019 - 04:12 PM

Yeah, sorry. I got my sizes mixed up, and was thinking that size_t varied by type, but it doesn't.
Was This Post Helpful? 0
  • +
  • -

#43 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 10 July 2019 - 12:12 PM

Is this it? (compiled from terminal instead of Code::Blocks)

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-solus-linux/8/lto-wrapper
Target: x86_64-solus-linux
Configured with: ../configure --prefix=/usr --with-pkgversion=Solus --libdir=/usr/lib64 --libexecdir=/usr/lib64 --with-system-zlib --enable-shared --enable-threads=posix --enable-gnu-indirect-function --enable-__cxa_atexit --enable-plugin --enable-gold --enable-ld=default --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --enable-lto --with-gcc-major-version-only --with-bugurl=https://dev.solus-project.com/ --with-arch_32=i686 --enable-linker-build-id --with-linker-hash-style=gnu --with-gnu-ld --build=x86_64-solus-linux --target=x86_64-solus-linux --enable-languages=c,c++,fortran
Thread model: posix
gcc version 8.3.1 20190320 (Solus)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib64/gcc/x86_64-solus-linux/8/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -o /tmp/ccZNGoHg.s
GNU C++14 (Solus) version 8.3.1 20190320 (x86_64-solus-linux)
compiled by GNU C version 8.3.1 20190320, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.20-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib64/gcc/x86_64-solus-linux/8/../../../../x86_64-solus-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib64/gcc/x86_64-solus-linux/8/../../../../include/c++/8
/usr/lib64/gcc/x86_64-solus-linux/8/../../../../include/c++/8/x86_64-solus-linux
/usr/lib64/gcc/x86_64-solus-linux/8/../../../../include/c++/8/backward
/usr/lib64/gcc/x86_64-solus-linux/8/include
/usr/lib64/gcc/x86_64-solus-linux/8/include-fixed
/usr/include
End of search list.
GNU C++14 (Solus) version 8.3.1 20190320 (x86_64-solus-linux)
compiled by GNU C version 8.3.1 20190320, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version isl-0.20-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0ea6fa03f76ef5ab200a6f3f0c7a0ea7
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/cc31DFAB.o /tmp/ccZNGoHg.s
GNU assembler version 2.32 (x86_64-solus-linux) using BFD version (GNU Binutils) 2.32
COMPILER_PATH=/usr/lib64/gcc/x86_64-solus-linux/8/:/usr/lib64/gcc/x86_64-solus-linux/8/:/usr/lib64/gcc/x86_64-solus-linux/:/usr/lib64/gcc/x86_64-solus-linux/8/:/usr/lib64/gcc/x86_64-solus-linux/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-solus-linux/8/:/usr/lib64/gcc/x86_64-solus-linux/8/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-solus-linux/8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib64/gcc/x86_64-solus-linux/8/collect2 -plugin /usr/lib64/gcc/x86_64-solus-linux/8/liblto_plugin.so -plugin-opt=/usr/lib64/gcc/x86_64-solus-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccdQ9JuW.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /usr/lib64/ld-linux-x86-64.so.2 /usr/lib64/gcc/x86_64-solus-linux/8/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-solus-linux/8/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-solus-linux/8/crtbegin.o -L/usr/lib64/gcc/x86_64-solus-linux/8 -L/usr/lib64/gcc/x86_64-solus-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-solus-linux/8/../../.. /tmp/cc31DFAB.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-solus-linux/8/crtend.o /usr/lib64/gcc/x86_64-solus-linux/8/../../../../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'

This post has been edited by Xrey274: 10 July 2019 - 12:12 PM

Was This Post Helpful? 0
  • +
  • -

#44 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,977
  • Joined: 05-May 12

Re: Segmentation fault on vectors.

Posted 10 July 2019 - 04:16 PM

Sort of. I was hoping that you would see that output in the Code::Blocks output window so that you could potentially see any diagnostics and other output.
Was This Post Helpful? 0
  • +
  • -

#45 Xrey274   User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 294
  • Joined: 10-December 16

Re: Segmentation fault on vectors.

Posted 11 July 2019 - 03:13 AM

Do you see anything that could tell you something?
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5