P
pozz
Hi all!
In source.h, I define a struct and the symbolic names of the indexes:
--- source.h ---
typedef struct {
type field1;
type field2;
...
type fieldm;
} mystruct;
extern mystruct mys;
enum MYSTRUCT_INDEX {
RECORD1 = 0,
RECORD2,
...
RECORDn,
};
---
In source.c, I initialize the struct:
--- source.c ---
#include "source.h"
mystruct mys[] = {
{ <field11>, <field12>, ..., <field1m> },
{ <field21>, <field22>, ..., <field2m> },
...
{ <fieldn1>, <fieldn2>, ..., <fieldnm> },
};
---
In this way, in a third C source file I can include "source.h" and access
the array by the symbolic names:
--- third.c ---
#include "source.h"
....
if( mys[RECORDx].fieldy==... )
....
---
This system works well but there is a drawback. When I insert a new record in
the middle of the array I should remember to change and re-align the enumeration
in the source.h file. Is there a way, maybe using some preprocessor directives,
so that I modify/reorder/insert the records only in a point and maintain the
coherence in the enumeration?
In source.h, I define a struct and the symbolic names of the indexes:
--- source.h ---
typedef struct {
type field1;
type field2;
...
type fieldm;
} mystruct;
extern mystruct mys;
enum MYSTRUCT_INDEX {
RECORD1 = 0,
RECORD2,
...
RECORDn,
};
---
In source.c, I initialize the struct:
--- source.c ---
#include "source.h"
mystruct mys[] = {
{ <field11>, <field12>, ..., <field1m> },
{ <field21>, <field22>, ..., <field2m> },
...
{ <fieldn1>, <fieldn2>, ..., <fieldnm> },
};
---
In this way, in a third C source file I can include "source.h" and access
the array by the symbolic names:
--- third.c ---
#include "source.h"
....
if( mys[RECORDx].fieldy==... )
....
---
This system works well but there is a drawback. When I insert a new record in
the middle of the array I should remember to change and re-align the enumeration
in the source.h file. Is there a way, maybe using some preprocessor directives,
so that I modify/reorder/insert the records only in a point and maintain the
coherence in the enumeration?