Florian Moser
Florian Moser

Reputation: 121

typedef struct: unknown name

I am confused by my actual problem... Could also be my mistake

Short description with code:

rtc.h

#ifndef RTC_H_
#define RTC_H_

typedef struct timestamp_t
{
    uint8_t year,month,day,hour,minute,second;
}timestamp_t;

#endif /* RTC_H_ */

lpwa.h

#ifndef LPWA_H_
#define LPWA_H_

#include "rtc.h"

timestamp_t lpwa_ntp_to_stamp(char*); //shows error: unknown name timestamp_t

#endif /* LPWA_H_ */

lpwa.c

#include "lpwa.h"

timestamp_t lpwa_ntp_to_stamp(char *text) //no problem
{
    ...
}

If I copy the typedef struct to lpwa.h it says "confliction types for timestamp_t"

Am I missing something or is this just not possible?

Upvotes: 2

Views: 163

Answers (1)

RubberBee
RubberBee

Reputation: 150

This is an answer compiled from my debugging recommendations which helped OP to find the actual problem:

  • The shown code should not exhibit the described problem. This actually is helpful information, because it means that the structure of your actual code is different and you need to find that difference to trace the problem to the root.
  • The problem is probably in the include order, aka include tree, being different than you think.
  • Inserting #error Header A is compiled #error Header B is compiled generously in all likely and unlikely places of your project will give you an idea of the actual include tree, allowing you to look for differences to the imagined include tree. (Use #warning if your compiler supports it, then you get more than only the first #error encountered.)
  • The constructive way to debug this is to make a StackOverflow-style minimal reproducible example.
  • If making a classic MRE/MCVE ( http://stackoverflow.com/help/mcve ) seems too much work (it is not, trust me), then try making a MRE of what you think happens, from scratch. That will at least show you that what you think happens is NOT what actually happens. This is also helpful information, though making use of it requires experience and discipline. (Thanks for not feeling mocked here.)
  • Keep in mind that each source code file "*.c" is the root of another include tree.
  • Playing with #error will also alert you of the possible problem that you look at different files (e.g. in your editor) than the compiler actually processes. (Again, not mocking. That happens more often, to me, than I'd like to admit....)

Above is general.

Specifically in your case, I suspect that there is a hidden/indirect #include "lwpa.h" inside rtc.h, between the shown include and the shown typedef. (And I think you confirmed that.)

Upvotes: 4

Related Questions