0

Header (render.h):

struct interface_tile
{
    char tile[30][120];
};

int render_map_entities(int player_x, int player_y, interface_tile map);

C file (render.c):

int render_map_entities(int player_x, int player_y, interface_tile map)
{
    //Code
}

Main C file:

#include"render.h"

GCC Compile:

render.h:6:53: error: unknown type name 'interface_tile'
    6 | int render_map_entities(int player_x, int player_y, interface_tile map);
      |                                                     ^~~~~~~~~~~~~~

typedef in the header doesn't solve the problem, but maybe I just used it incorrectly.

thank you in advance

Oduen
  • 3
  • 2
  • 2
    You didn't show the typedef you tried. A *correct* typedef would definitely solve the issue. Alternatively, you could correct your function prototype. – Konrad Rudolph Feb 06 '23 at 14:32
  • In C, `struct interface_tile { ... }` declares a type named `struct interface_tile`. Not one named `interface_tile`. (C++ differs in this regard.) – John Bollinger Feb 06 '23 at 14:33
  • Opinions differ in this area, but I am in the camp that recommends avoiding `typedef` for structure types. To use a structure type declared elsewhere without relying on a typedef, you (1) give the structure a tag (which you have done), and (2) refer to the type via the form `struct the_tag`. – John Bollinger Feb 06 '23 at 14:48
  • Well, I do not know how to write typedef and structures correctly since I am just learning C and I would be very grateful if you could tell me. – Oduen Feb 06 '23 at 14:54
  • @John Bollinger " refer to the type via the form `struct the_tag` " how to refer to the type? – Oduen Feb 06 '23 at 15:02
  • Are you asking what I mean by "refer"? I just mean that wherever you want to declare an object of your structure type or to derive another type related to it (say a pointer to a structure or an array of structures) you use the keyword `struct` before the tag name. In this particular case, that would be `struct interface_tile`, as I already observed in a previous comment. Aso, this and more is well covered in the dupe targets. Do read some of the higher-scoring answers to those. – John Bollinger Feb 06 '23 at 15:29

0 Answers0