Reputation: 12516
I have wrote some files: main.c, functions.c, functions2.c, and header.h. The some functions in the functions.c, and functions2 use my some enums, and structures.
Where must I place my enums, and structures? How to write declarations for them in the functions.c, and functions2.c? My functions (from different files) have to see them.
For example, I have wrote such function's declarations in the header.h:
int func(void);
void func2(int);
But I don't know how it write for enums, and structures.
Regards
Upvotes: 0
Views: 92
Reputation: 1022
Declaring structures:
typedef struct <optional struct name>
{
int member1;
char* member2;
} <struct type name>;
Put whatever members you want in the struct in the format above, with any name you want. Then you use:
<struct type name> my_struct;
To declare instances of the struct.
Declaring enums:
typedef enum
{
value_name,
another_value_name,
yet_another_value_name
} <enum type name>;
Put whatever values in the enum as above, with any name you want. Then you use:
<enum type name> my_enum;
To declare instances of the enum.
Upvotes: 1
Reputation: 13979
Example for functions.c:
#include "header.h"
int func(void)
{
...
}
void func2(int)
{
}
Example for header.h:
#ifndef HEADER_H
#define HEADER_H
int func(void);
void func2(int);
enum eMyEnum
{
eZero = 0,
eOne,
eTwo
};
struct sMyStruct
{
int i;
float f;
};
#endif
Upvotes: 1