0
Console* initConsole(Controller* ctrl){
    if (ctrl == NULL)
        return NULL;
    Console* c = (Console*)malloc(sizeof(Console));
    c->ctrl = ctrl;
    return c;
}

expected '=', ',', ';', 'asm' or 'attribute' before '{' token

This error appears in one of my modules.For some functions the "{" wasn't on the same row as the header of the function so I pressed a backspace,saved and debuged.The module was clean but the error went to another module and I have no ideea of what's wrong.

reinierpost
  • 8,425
  • 1
  • 38
  • 70
Matt
  • 484
  • 5
  • 15
  • 3
    Missing semicolon in included header? – Daniel Fischer Apr 04 '13 at 18:22
  • 1
    It looks like one of `Console` or `Controller` is not a recognized type. Otherwise, the code seems likely to be sensible. – Jonathan Leffler Apr 04 '13 at 18:23
  • 1
    On a side note, this: `Console* c = malloc(sizeof(*c))` is preferable to `Console* c = (Console*)malloc(sizeof(Console));` – Ed S. Apr 04 '13 at 18:23
  • 1
    Try writing a simple hello world program that includes the same headers that your module does and compile it one-off. Do you get the same thing? If so, it's in the headers (lets you quickly eliminate anything else prior to what you posted). – Tim Post Apr 04 '13 at 18:26
  • @MateiMarius: Because A) http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc, and B) if you change the type of `c` then your call to malloc is wrong until you change the `sizeof` bit as well. However, if you use `*c` then `sizeof` will always return the correct number of bytes. – Ed S. Apr 04 '13 at 20:47

1 Answers1

3

I most often get this if I forget to put a semi-colon after a forward declaration (possibly in an included header)

tletnes
  • 1,958
  • 10
  • 30