I have some very long arrays. Sorting at runtime is possible. Sorting them also takes a lot of time. Moreover, new elements can be added in any order later, so I would like to sort them by value using the C preprocessor, or maybe there is some compiler flag (GCC)?
For example:
sometype S[] = { {somevals, "BOB", someothervals}, {somevals, "ALICE", someothervals}, {somevals, "TIM", someothervals}, }
should be sorted like this:
sometype S[] = { {somevals, "ALICE", someothervals}, {somevals, "BOB", someothervals}, {somevals, "TIM", someothervals}, }
solvableOk, here is my solution:
- Manually copy and paste each array into a temporary tobesorted.c file
- Column 2
sort -b -i --key=2 tobesorted.c : sort -b -i --key=2 tobesorted.c - Copy and paste the output back into the source file.
Actually, it would be nice to be able to call “sorting” directly from the preprocessor (I had the hope that at least GCC somehow supported such functions, but it seems that this is not so).
c gcc sorting c-preprocessor
psihodelia
source share