我有很多非常长的数组.没有运行时排序是可能的.手动排序也很耗时.此外,可以在以后以任何顺序添加新元素,因此我想使用C预处理器按值对它们进行排序,或者可能有任何编译器标志(GCC)?
例如:
sometype S[] = {
{somevals, "BOB", someothervals},
{somevals, "ALICE", someothervals},
{somevals, "TIM", someothervals},
}
Run Code Online (Sandbox Code Playgroud)
必须这样排序:
sometype S[] = {
{somevals, "ALICE", someothervals},
{somevals, "BOB", someothervals},
{somevals, "TIM", someothervals},
}
Run Code Online (Sandbox Code Playgroud)
好的,这是我的解决方案:
sort -b -i --key=2 tobesorted.c实际上,有一种可能性直接从预处理器调用"排序"会很好(我希望至少GCC能以某种方式支持这些功能,但似乎它没有).