Reputation: 511
I have a large static const byte array that I will be hard defining. This ends up with about 500 lines of wall-of-text type code that is a bit of an eyesore among the rest of the normal flow of the file. In addition, the byte contents of the file is something that would likely be generated by a script type parser.
static const uint8_t largeArray[0x4000]
{
// About 500 lines of content here.
}
In this situation, is it acceptable style to simply create another .c file and then simply include it in my original source file in order to make the 500 lines turn into one? In general I despise including .c in another .c but I'm not sure what the recommended practice is for situations like this.
static const uint8_t largeArray[0x4000]
{
#include "ArrayContents.c" // One line, but not nice file structure.
}
Upvotes: 2
Views: 193
Reputation: 14718
It is acceptable and may typically happen where the large array is generated by some other process, but typically you would want to give the file a different suffix, like .hc
instead of .c
so that people are not confused about that it is neither a header file or a source file in its own.
An alternative is to just have the content of the file in a different .c file, with just;
const uint8_t largeArray[0x4000]
{
// About 500 lines of content here.
}
and then just declare it an extern in the file where you are using it, e.g.;
extern const uint8_t largeArray[0x4000];
Upvotes: 3