Returning struct containing array

后端 未结 3 1139
温柔的废话
温柔的废话 2020-12-03 02:46

The following simple code segfaults under gcc 4.4.4

#include

typedef struct Foo Foo;
struct Foo {
    char f[25];
};

Foo foo(){
    Foo f =          


        
3条回答
  •  [愿得一人]
    2020-12-03 03:24

    On MacOS X 10.7.2, both GCC/LLVM 4.2.1 ('i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)') and GCC 4.6.1 (which I built) compile the code without warnings (under -Wall -Wextra), in both 32-bit and 64-bit modes. The programs all run without crashing. This is what I'd expect; the code looks fine to me.

    Maybe the problem on Ubuntu is a bug in the specific version of GCC that has since been fixed?

提交回复
热议问题