K
Kieran Simkin
I have in my project in main.c a number of arrays defined like this (outside
of any functions):
char muser[256], mpass[256];
I'm declaring them in a number of other .c files (inside functions) like
this:
extern char muser[], mpass[];
However, in one of these functions outside of main.c I need to snprintf into
these buffers. Usually when using snprintf I call it like this:
snprintf(muser, sizeof muser, "text");
My problem is that sizeof does not work on extern arrays declared as above -
GCC returns the following error:
config.c:41: sizeof applied to an incomplete type
What's the best solution to this problem? I'm assuming it's valid to specify
an array's size when declaring it with extern, but I'd rather not have magic
numbers scattered all over my source files. Is there any way I can use
sizeof or similar on externally defined arrays without specifying array
dimensions in each source file?
Thanks.
~Kieran Simkin
Digital Crocus
http://digital-crocus.com/
of any functions):
char muser[256], mpass[256];
I'm declaring them in a number of other .c files (inside functions) like
this:
extern char muser[], mpass[];
However, in one of these functions outside of main.c I need to snprintf into
these buffers. Usually when using snprintf I call it like this:
snprintf(muser, sizeof muser, "text");
My problem is that sizeof does not work on extern arrays declared as above -
GCC returns the following error:
config.c:41: sizeof applied to an incomplete type
What's the best solution to this problem? I'm assuming it's valid to specify
an array's size when declaring it with extern, but I'd rather not have magic
numbers scattered all over my source files. Is there any way I can use
sizeof or similar on externally defined arrays without specifying array
dimensions in each source file?
Thanks.
~Kieran Simkin
Digital Crocus
http://digital-crocus.com/