Typedef was ignored compile error

I have a number of structs that I have typedef’d to store data from single instance objects like shown in the thread below. I am getting a the following error when I attempt to compile. I added #pragma SPARK_NO_PREPROCESSOR to my main.ino but not sure if I need to include that in all of my header files. I have several custom classes all using the “singleton” method and structs to track config/state data across different parts of my app. MyApp_H.h is similar to the Particle/application.h in that it is included by all custom classes and contains includes to all custom classes. I would post the code but it is getting rather large at this point and I doubt anyone would want to troll through all that so hoping it is something that is known or a silly mistake on my part.

MyApp_Time.h:14:1: warning: 'typedef' was ignored in this declaration [enabled by default]
 };
 ^
MyApp_Time.h:22:1: warning: 'typedef' was ignored in this declaration [enabled by default]
 };
 ^
In file included from MyApp_H.h:15:0,
                 from MyApp.h:4,
                 from MyApp.cpp:1:

You are only showing warings, where is the error message?

There is no need to add the #pragma in .h or .cpp files.

1 Like

Hi @LukeUSMC

Is preprocessor #pragma above or below the #include statements for your classes?

It should be above, with a few blank lines (for safety) and then the #pragma.

1 Like

So that was something else I needed to figure out, warnings won’t cause a compile failure? I do have an error right before compile termination, I think it is related to one of my typedef’d structs (undefined reference, see below). Everything else looks proper to me…but then again, it is me. Thanks for taking a look!
typedef in header file

typedef struct devicetime_t {
  uint8_t hour;
  uint8_t minute;
};

Use in implementation/cpp

time_t createTimestamp(devicetime_t xTime){
  struct tm t;
  time_t t_of_day;
  t.tm_year = Time.year();
  t.tm_mon = Time.month();           // Month, 0 - jan
  t.tm_mday = Time.day();          // Day of the month
  t.tm_hour = xTime.hour;
  t.tm_min = xTime.minute;
  t.tm_sec = 0;
  t.tm_isdst = -1;        // Is DST on? 1 = yes, 0 = no, -1 = unknown
  t_of_day = mktime(&t);
  return t_of_day;
}

Error:

Pacsui_Time.cpp:14: undefined reference to `Pacsui_Time::createTimestamp(devicetime_t)'
collect2: error: ld returned 1 exit status

So IF I do need the preprocessor statement in which files should it be placed? Right now it is only in main.ino (with only two blank lines above it), I couldn’t find anything that said for sure which files it belongs in.
Main.ino (self explanatory)
Pacsui_H.h (rip off the application.h header)
Class1.h/cpp
Class2.h/cpp
etc.

Try this instead

typedef struct  {
  uint8_t hour;
  uint8_t minute;
} devicetime_t ;

Here is a nice primer
http://stackoverflow.com/questions/1675351/typedef-struct-vs-struct-definitions

Didn’t I already answer that?

Only .ino files get the wiring preprocessor treatment, so if you need it then only in an .ino.

1 Like

Thank you, I missed it the first time…won’t miss that again!

But I did find what else I was missing…in the implementation file… facepalm

time_t createTimestamp(devicetime_t xTime)

to

time_t Pacsui_Time::createTimestamp(devicetime_t xTime)
1 Like