Accessing out-of-bounds elements of dynamically allocated arrays / w/o SegFault

前端 未结 4 2029
粉色の甜心
粉色の甜心 2021-01-24 18:48

I\'m developing a program in C that uses an array of linked lists (a primitive hash table) as a data type to represent certain date information. The array has twelve elements c

4条回答
  •  终归单人心
    2021-01-24 19:36

    SegFaults are OS creatures. They are thrown when a process tries to access memory that does not belong to it, and are not part of the C language. In C, accessing out of bounds elements is just undefined behavior, which means it might fail, and it might not. If, for instance, the memory allocator has provided a memory chunk larger than what you've asked for the array, the OS won't care if you go out of bound, because you'll be accessing memory that does belong to your process. When this is the case, you just get a bug in your program.

提交回复
热议问题