I have searched the forum and spent an hour going through several pages of Google search results, but still can't find a solution to my problem. The compiler returns the following two errors on several different occasions using very similar code:
error: invalid use of incomplete type 'struct stName' error: forward declaration of 'struct stName'
I am using a header file in which my structs are declared:
An incomplete type is usually the result of something like this:
struct Foo;
Foo f; //Error incomplete
Whereas giving the struct a definition resolves this:
struct Foo{};
Foo f; //No error
..Or you declare your struct as aaabbb, but use AAABBB << notice case.
remove the 'struct's from every where apart from the declaration to avoid faulty syntax accidentally declaring a new, incomplete type. C++ does not require it unless you use the same identifier for something like a function name.
I have to go out soon, but this example and others may be able to help you ( with the real code )
I checked for case mistakes, but couldn't find any.
Removing the 'struct's from everything except the declarations produced errors saying:
error: 'stName' was noch declared in this scope
I'm assuming, this means there's something wrong with my header file?
Here's the actual code from the header called "structures.h"
#ifndef structures_h
#define structures_h
struct stThTime{
unsigned long Time_r;
unsigned long Time_s;
unsigned long Time_c;
int Time_z;
unsigned long Time_d;
unsigned long Time_p;
unsigned long Time_e;
unsigned long Time_f;
};
struct stThread{
char name[20];
void function(){
Serial.println(name);
}
stThTime *time;
int prio;
int state;
};
struct stThreadTable{
int numThreads;
int numReadyThreads;
int activeThread;
stThread *Thread[3];
};
#endif
DudefromGermany:
I checked for case mistakes, but couldn't find any.
Removing the 'struct's from everything except the declarations produced errors saying:
error: 'stName' was noch declared in this scope
I'm assuming, this means there's something wrong with my header file?
Here's the actual code from the header called "structures.h"
#ifndef structures_h
#define structures_h
struct stThTime{
unsigned long Time_r;
unsigned long Time_s;
unsigned long Time_c;
int Time_z;
unsigned long Time_d;
unsigned long Time_p;
unsigned long Time_e;
unsigned long Time_f;
};
struct stThread{
char name[20];
void function(){
Serial.println(name);
}
stThTime *time;
int prio;
int state;
};
struct stThreadTable{
int numThreads;
int numReadyThreads;
int activeThread;
stThread *Thread[3];
};
#endif
well, there indeed is no struct with the name "stName" defined in what you posted above :).
PaulS:
Zip up all of your code, and use the Additional Options... link to attach the zip file. Enough of the guessing games.
Here's the .zip file. There will most likely be other problems as well, I'm really only stuck on the errors related to the structs right now and was hoping to spare you the time to go through the rest of my code.
I'm sure you can agree that its probably an important part, seeing as your error is in there. No more silly little examples, I don't care that you can write a struct, I want to see how you use it.
I'm really only stuck on the errors related to the structs right now and was hoping to spare you the time to go through the rest of my code.
Strange how reluctant people are to posting their code. Seriously your problem would have been fixed by now if you posted the problem, not what you think is the problem.
When I download the attached .zip file, this is what's contained in the folder:
the sketch as .ino, the header file and a timer library just because I included it in the sketch to try something out.
There is more than that in there, your system has added a bunch of _MACOSX rubbish. My fault anyway I didn't see the .ino mixed in with the other stuff.
Here is a list of things you can go and fix first:
Change the include for local files ( sketch local ) to use quotes rather than '<>'
At the top of structures.h add #include "Arduino.h"
Correct the way you access members of object pointers.
If you accept a parameter which is a pointer, you must dereference it or use the pointer to member operator. Otherwise pass in a reference rather than a pointer. Also the time member is a pointer too.
Wrong:*
int cyc_time(stThread *time_check){
time_check.time.Time_z--;
Correct:*
int cyc_time(stThread *time_check){
time_check->time->Time_z--;
Or using a reference parameter:
int cyc_time(stThread &time_check){
time_check.time->Time_z--;
Once done, repost your sketch if you get more errors.
Sorry about that, obviously didn't see any of the junk on my system. I had used typedef struct until I read that this doesn't seem to work well with the compiler and forget to change the "." to "->". After changing the include tag it compiles fine without errors. The solution was a lot easier than expected Thanks a lot!!
typedefs work fine, using it to declare a struct is a C idiom.
In C++ reserve the use of typedefs to actually modifying a type in some way, or to re purpose a type with a different name.