C program compiled with cygwin in Windows works, segmentation fault under Linux. Is cygwin GCC 'bad'?

后端 未结 11 2131
半阙折子戏
半阙折子戏 2021-02-19 10:11

For my Programming 102 class we are asked to deliver C code that compiles and runs under Linux. I don\'t have enough spare space on my hard drive to install Linux alongside Wind

11条回答
  •  野的像风
    2021-02-19 11:14

    It's almost certainly a pointer error or buffer overrun, maybe an uninitialised variable.

    An uninitialised pointer will usually point at nothing, but sometimes it will point at something; reading from it or writing to it will typically crash the program, but then again it MIGHT not.

    Writing or reading from freed memory is the same story; you might get away with it, then again maybe not.

    These situations depend on exactly how the stack, heap are laid out and what the runtime is doing. It is quite possible to make a bad program that works on one compiler / runtime combination and not another, simply because on one it overwrites something that doesn't matter (so much), or that an uninitialised variable "happens" to contain a valid value for the context it's used in.

提交回复
热议问题