您需要创建一个全局数组,并显式初始化所有元素。这些元素应该是随机的,否则编译器可能会优化编译代码中的初始化程序列表。
首先,您需要一个单独的程序来生成你的阵列:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int len = 100000000;
int i;
srand(getpid());
printf("unsigned char buf[%d] = {\n", len);
for (i=0;i<len;i++) {
printf(" %hhu,", rand() & 0xff);
if (i%16==15) printf("\n");
}
printf("};\n\n");
return 0;
}
运行这和输出重定向到一个文件:
./array_generator > array.c
然后你会得到array.c这看起来是像这样:
unsigned char buf[1000000] = {
247, 223, 30, 51, 46, 247, 133, 136, 254, 225, 82, 135, 68, 176, 240, 7,
29, 245, 104, 203, 230, 83, 127, 189, 37, 5, 168, 105, 134, 9, 229, 125,
232, 3, 176, 23, 251, 53, 159, 249, 22, 241, 128, 90, 161, 112, 97, 191,
101, 202, 138, 75, 29, 10, 9, 66, 15, 177, 171, 149, 186, 145, 18, 163,
...
};
然后,您将其包含在您的主要来源中:
#include "array.c"
“scalable”是什么意思? –
*“抽象问题”* - 不,你不能这么简单,我很好奇。你为什么真的在问? :) – StoryTeller
就像'echo abcd >> myprogram.exe'一个选项? –