P
pozzugno
I have a module in which I define many const arrays of int of different
lengths (someone knows SNMP OIDs?).
In the same module I really use these arrays and the length is calculated by
a simple preprocessor macro (OID_LENGTH).
--- oid.c --
#define OID_LENGTH(oid) (sizeof(oid) / sizeof(oid[0]))
const int oidParam1[] = { 1, 1, 3 };
const int oidParam2[] = { 1, 2 };
const int oidParam1[] = { 2, 1 };
const int oidParam1[] = { 2, 2, 5, 4 };
int print_oid(int *oid, size_t size) {
while(size--) {
printf("%d", *oid++);
if (size) putchar('.');
}
return putchar('\n');
}
....
print_oid(oidParam1, OID_LENGTH(oidParam1));
....
---
Now the application has grown and I want to create a different module that
uses the same arrays defined in oid.c. Certainly I can write the definition
in a "oid.h" include as extern, but I can't specify the length.
--- mib.h ---
extern int oidParam1[];
extern int oidParam2[];
int print_oid(int *oid, size_t size);
---
For example, how can I print oidParam1 with print_oid() calling it from a
different module? I couldn't use OID_LENGTH macro (even if I move its
declaration to mib.h).
Any suggestions?
lengths (someone knows SNMP OIDs?).
In the same module I really use these arrays and the length is calculated by
a simple preprocessor macro (OID_LENGTH).
--- oid.c --
#define OID_LENGTH(oid) (sizeof(oid) / sizeof(oid[0]))
const int oidParam1[] = { 1, 1, 3 };
const int oidParam2[] = { 1, 2 };
const int oidParam1[] = { 2, 1 };
const int oidParam1[] = { 2, 2, 5, 4 };
int print_oid(int *oid, size_t size) {
while(size--) {
printf("%d", *oid++);
if (size) putchar('.');
}
return putchar('\n');
}
....
print_oid(oidParam1, OID_LENGTH(oidParam1));
....
---
Now the application has grown and I want to create a different module that
uses the same arrays defined in oid.c. Certainly I can write the definition
in a "oid.h" include as extern, but I can't specify the length.
--- mib.h ---
extern int oidParam1[];
extern int oidParam2[];
int print_oid(int *oid, size_t size);
---
For example, how can I print oidParam1 with print_oid() calling it from a
different module? I couldn't use OID_LENGTH macro (even if I move its
declaration to mib.h).
Any suggestions?