0

I have a struct declared in program.h

typedef struct{
    int size;
    int colour;
    int h;
    int w;
}model;

I use it in program.c but I also want to use it in interface.c in a function.

in interface.h I have

#include "program.h"

void updateF(model* novomodelo);

in interface.c

#include "interface.h"

void updateF(model* novomodelo){
....
}

but I'm getting

error: expected ')' before '*' token

What am I doing wrong? What is the correct way to do this? thanks

mehrlicht
  • 75
  • 1
  • 11
  • 1
    You need to use `#include "program.h"` and `#include "interface.h"`. You are missing the `"`s (the double quotes) in the posted code. See http://en.cppreference.com/w/cpp/preprocessor/include for further details. – R Sahu Dec 28 '17 at 23:24
  • Code is with "s. I forgot the double quotes in the post. edited. thanks – mehrlicht Dec 28 '17 at 23:29
  • Agreed with R Sahu. But also make sure your compiler supports anonymous structs; it if doesn't, change `typedef struct {` to `typedef struct model {` – torstenvl Dec 28 '17 at 23:29
  • After the fix to the `#include` lines, the code looks ok to me. Please post a [mcve]. – R Sahu Dec 28 '17 at 23:33
  • Thank you but it hasn't solved. – mehrlicht Dec 28 '17 at 23:37
  • 1
    Untagged structs are perfectly standard, @torstenvl, at least all the way back to C89. Are you thinking of a particular compiler? Because if I ever ran into one that rejected untagged structure types then I would be try to keep it as far away from me as possible. – John Bollinger Dec 28 '17 at 23:40
  • 1
    @mehrlicht, I'm inclined to think that the picture is different than you have portrayed. The error message you present appears to indicate that the compiler does not recognize `model` as a type name, But the code fragments you present suggest that it should do. This is why we generally expect questions to demonstrate the problem via a *bona fide* [mcve]. Your code fragments do not constitute an MCVE, and we are unlikely to help you until you provide one. – John Bollinger Dec 28 '17 at 23:47
  • I think I solved it. Somehow I needed to have interface.c like this: #include "interface.h" struct model; void updateF(struct model* novomodelo){ .... } – mehrlicht Dec 29 '17 at 00:17
  • @John Bollinger You seem to be right (and thanks for the correction on terminology - anonymous `struct`s are wholly different from untagged ones). I know lack of support for using `typedef` on an untagged `struct` had bitten me in the butt before... if I had to guess it would have been on an old 32-bit SPARC machine running SunOS 5-point-something-or-other. Good times. – torstenvl Dec 29 '17 at 04:26
  • @mehrlicht That isn't a solution, it's a workaround. Somehow your typedef isn't functioning and propagating correctly. You should try and figure out why. – torstenvl Dec 29 '17 at 04:28
  • That workaround led to an error later on so I had to find another turnaround which was declaring the functions in the headers where the structs are and defining those functions in the c's that I wanted.... – mehrlicht Dec 29 '17 at 13:40

0 Answers0