I am aware there are multiple questions regarding this problem but none provides a solution under my constraints.
I am working on a project where a header file mips_cpu.h
with a certain API is given. I am intended to develope its implementation without altering the header file. This API includes a structure declared in a file mips_cpu.cpp
as:
struct mips_cpu_impl;
typedef struct mips_cpu_impl *mips_cpu_h;
I have then defined this structure in mips_cpu.cpp
as:
struct mips_cpu_impl{
//Program Counter
uint32_t pc;
uint32_t pcN;
//General Purpose Registers
uint32_t GPReg[32];
//Special registers for MUL / DIV instructions
uint32_t LO;
uint32_t HI;
----- more code ---
};
The problem comes when using this structure in another file mips_cpu_instruction.cpp
. When I have this code:
mips_error ADDI(mips_cpu_h state, uint8_t rs, uint8_t rt, uint16_t imm){
uint64_t check = state->GPReg[rs] + imm;
uint32_t tmp = state->GPReg[rs] + imm;
...
more code and appropriate return
}
state
then gives the error: use of undefined type 'mips_cpu_imps'
Including the declaration of the structure in the header file solves the problem but I am not supposed to change the header files. Also the header files contain guards, which I dont fullly understand but might be relevant?