Blah.h since it is a declartion of a struct. I would also add a header guard (ref: Organizing Code Files in C and C++ ) so it would look like this:// Blah.c or Blah.h
typedef struct clsBlah{
int a, b;
}BLAH;
///////////////////////
#ifndef BLAH_H
#define BLAH_H
typedef struct clsBlah{
int a, b;
}BLAH;
#endif // BLAH_HFoo.h since it is a declartion of a struct. I would also add a header guard so it would look like this:// Foo.c or Foo.h
typedef struct clsFoo{
BLAH blah;
}FOO;
Finally:#ifndef FOO_H
#define FOO_H
#include "./blah.h"
typedef struct clsFoo{
BLAH blah;
}FOO;
void useFoo(FOO f); // See next section on why this is here.
#endif // FOO_H
Would be in foo.c since it is code. The function declaration should be in foo.h. This would now look like:void useFoo(FOO f){
f.blah.a = 0;
}
Some other notes: Don't use Full caps for struct/class names (eg FOO). Full caps are normally used for constants.#include "./foo.h"
void useFoo(FOO f){
f.blah.a = 0;
}
The function useFoo should pass by pointer or reference rather then by value because:
- You are trying to modify the object you passed in. If you pass by value, you are only modifying the function's local copy.
- Rather then copying a large struct full of data, you are only passing the memory address where the data is. Much more efficent.
Bookmarks