For point 3 above within Dathan's answer, another way of swapping, you can swap variables in an unconventional manner using xor.
int = 3, y = 4;
x = x ^ y;
y = y ^ x;
x = x ^ y;
Now x and y are swapped! :)
Another thing, when you are dividing something with 2, it is better to use shift right operator. Same could be said for multiplying by 2, shift left.
In the old Borland C compiler, there was a _stklen
property which you can assign in order to reduce stack size and code. I haven't seen anything like that nowadays as compiler technology has advanced since.
When using malloc, it would be better to calloc instead as it initializes memory to zero instead.
Usage of the ternary operator instead of the if/else statement is apparently faster, I guess that compiler writers have got more smarter with regards to machine code generation. I simply cannot provide proof of that in that regard, but it was held true back then when Borland C 3.01 ruled the roost.
Inlining code with assembly routines.
I like this question topic as it reminds me of the old days when memory was precious and having to squeeze a pint into a quart pot and used the hocus pocus tricks of the x86 code. Thanks for posting this question Mr.Database.
Take care,
Tom.