Search code examples
cudanvcc

Why does the typedefed struct fail to compile with NVCC?


typedef struct {
    long long int mem_0;
} Tuple1;

typedef struct {
    int tag;
    union {
        struct Tuple1 Union0Case0;
    } data;
} Union0;

C:/Users/Marko/Documents/Visual Studio 2015/Projects/Multi-armed Bandit Experiments/SpiralExample/bin/Release/cuda_kernels.cu(10): error: incomplete type is not allowed

The above does in fact compile on the GCC 5.3.0 compiler. When I change it to this, it works:

struct Tuple1 {
    long long int mem_0;
};

struct Union0 {
    int tag;
    union {
        struct Tuple1 Union0Case0;
    } data;
};

Solution

  • To summarize the comments into an answer so that this question falls off the unanswered queue for the CUDA tag.

    This:

    typedef struct {
        long long int mem_0;
    } Tuple1;
    

    defines a type containing an unnamed structure. There is no definition of struct Tuple1.

    This, on the other hand, defines such a structure:

    struct Tuple1 {
        long long int mem_0;
    };
    

    and this defines a type containing such a named structure:

    typedef struct Tuple1 {
        long long int mem_0;
    } Tuple1_t;
    

    Any of the latter two would be compatible with your other code.