我不喜欢这些答案,所以我自己做了。我不知道这是否是ANSI C,它只是默认模式下的GCC 4.2.1。我永远都不记得括号,所以我从我的数据子集开始,并与编译器错误消息作斗争,直到它关闭为止。可读性是我的首要任务。
// in a header:
typedef unsigned char uchar;
struct fields {
uchar num;
uchar lbl[35];
};
// in an actual c file (I have 2 in this case)
struct fields labels[] = {
{0,"Package"},
{1,"Version"},
{2,"Apport"},
{3,"Architecture"},
{4,"Bugs"},
{5,"Description-md5"},
{6,"Essential"},
{7,"Filename"},
{8,"Ghc-Package"},
{9,"Gstreamer-Version"},
{10,"Homepage"},
{11,"Installed-Size"},
{12,"MD5sum"},
{13,"Maintainer"},
{14,"Modaliases"},
{15,"Multi-Arch"},
{16,"Npp-Description"},
{17,"Npp-File"},
{18,"Npp-Name"},
{19,"Origin"}
};
数据可能以制表符分隔的文件开始,您可以搜索该数据并替换成其他内容。是的,这是Debian的东西。因此,一对外部{}(表示数组),然后对内部的每个结构另外一对。之间用逗号分隔。严格将内容放在标头中不是必须的,但是我的结构中已有大约50个项目,因此我希望将它们放在一个单独的文件中,既可以避免代码混乱,又可以更轻松地替换。