Originally Posted by
MartinR
By bad formatting I meant the fact that the author doesn't use curly braces
One way to get around this for small amounts of code like this is to type it out yourself. That way you will unconciously reformat it to your liking, add notes as needed, etc. You can easily add braces everywhere you want them, rename variables, etc. Example:
Code:
#if !defined MAXHEAP || MAXHEAP < 1
#define MAXHEAP 10
#endif
static int heap[MAXHEAP];
void *new_(const void *type, ...) // I'm calling it new_ to make this easier
// to use with C++ compilers.
{
for (int *p = heap+1; p<heap+MAXHEAP; ++p) {
if (*p == NULL) {
break;
}
}
assert(p < heap+MAXHEAP);
*p = MAXHEAP; /* Before an object is added to a set, we let it contain the
impossible index value MAXHEAP so that new() cannot find
it again. (See p.5) */
return p;
}
If you prefer you can also use automatic formatter programs like GNU indent to do much of the work for you.