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.
我有一个很大的静态const字节数组,我很难定义。最终会有大约500行的文本墙类型代码,这些代码在文件的其余正常流程中有点像眼睛。此外,文件的字节内容可能由脚本类型解析器生成。
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.
在这种情况下,简单地创建另一个.c文件然后只是将其包含在我的原始源文件中以便将500行变成一个是可接受的样式吗?一般来说,我在另一个.c中鄙视包括.c但我不确定这种情况的推荐做法是什么。
static const uint8_t largeArray[0x4000]
{
#include "ArrayContents.c" // One line, but not nice file structure.
}
1 个解决方案
#1
3
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.
这是可以接受的,通常可能发生在大型数组由其他进程生成的地方,但通常你会想给文件一个不同的后缀,比如.hc而不是.c,这样人们就不会对它既不是一个混淆头文件或源文件本身。
An alternative is to just have the content of the file in a different .c file, with just;
另一种方法是将文件的内容放在不同的.c文件中,只需;
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,例如;
extern const uint8_t largeArray[0x4000];
#1
3
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.
这是可以接受的,通常可能发生在大型数组由其他进程生成的地方,但通常你会想给文件一个不同的后缀,比如.hc而不是.c,这样人们就不会对它既不是一个混淆头文件或源文件本身。
An alternative is to just have the content of the file in a different .c file, with just;
另一种方法是将文件的内容放在不同的.c文件中,只需;
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,例如;
extern const uint8_t largeArray[0x4000];