-1

I've got a structure of this type :

#define SUDOKU_SIZE 9
typedef struct {
   int grid[SUDOKU_SIZE][SUDOKU_SIZE];
} sudoku_t;

But when I want to create one : struct sudoku_t sudo;

I got this error : error: storage size of ‘s’ isn’t known

Thanks

Cariamole
  • 296
  • 2
  • 10

1 Answers1

5

By using typedef, you create a new type; you can simply reference it by its name sudoku_t (instead of struct sudoku_t). So instead of struct sudoku_t s; write

sudoku_t s;

If for some reason you actually want to create a named struct, drop the typedef:

struct sudoku_t {
   int grid[SUDOKU_SIZE][SUDOKU_SIZE];
};

int main() {
    struct sudoku_t s;
}
phihag
  • 278,196
  • 72
  • 453
  • 469
  • 2
    Good point, OP, if you want to use both (with or without `struct` keyword) use `typedef struct sudoku_t {int grid[SUDOKU_SIZE][SUDOKU_SIZE];} sudoku_t;` – David Ranieri May 14 '16 at 17:56
  • 1
    What's so strange about creating a named struct? Some of us prefer to use struct tags and drop the typedefs. – Keith Thompson May 14 '16 at 18:08
  • @KeithThompson Yeah, you're right. I've removed the prejudiced wording in this answer. – phihag May 14 '16 at 18:11