March 1st, 2020 at 10:01 PM
As compact as possible, with verbosity coming from basic comments explaining functionality so I don't need to look too hard to find what something does.
That being said, I do mostly write native/compiled stuff, so performance benefits are usually pretty negligible. gcc and g++ automatically compile typically slow operations to faster ones, like this:
The fastest or most compact even/odd calculator I've seen in C looked something like this:
Ternary operators, bitwise and pointer arithmetic. Very minified, and although I'm not actually compiling this to test it, you get the idea. The bloat comes from taking in arguments from the commandline.
I don't write huge projects or anything, so everything gets to be around a couple hundred lines, making it pretty easy to manage and generally fast to compile.
The largest code segments I've written were exploits or malware PoC's, and that's because you'd need to write shellcode as well, then compile it, rip out the .text segment from the binary, then make a byte array out of it to use with WriteProcessMemory or whatever from WinAPI/MemoryAPI.
That being said, I do mostly write native/compiled stuff, so performance benefits are usually pretty negligible. gcc and g++ automatically compile typically slow operations to faster ones, like this:
Code:
int i = 17;
int j = i / 2;
//j compiles to i >> 1, or bitshift right by one
int j = i % 2;
//compiles to i & 1 (bitwise AND with 0x1 to isolate the last bit)
The fastest or most compact even/odd calculator I've seen in C looked something like this:
Code:
#include <stdio.h>
int main(int argc, char* argv[]){
!(argc & 1) ? return 1 : 1;
const char* a = "odd\0even\0";
int(argv[1]) & 1 ? printf(a) : printf(*a + 4);
return 0;
}
Ternary operators, bitwise and pointer arithmetic. Very minified, and although I'm not actually compiling this to test it, you get the idea. The bloat comes from taking in arguments from the commandline.
I don't write huge projects or anything, so everything gets to be around a couple hundred lines, making it pretty easy to manage and generally fast to compile.
The largest code segments I've written were exploits or malware PoC's, and that's because you'd need to write shellcode as well, then compile it, rip out the .text segment from the binary, then make a byte array out of it to use with WriteProcessMemory or whatever from WinAPI/MemoryAPI.