Recipe For Creating Small Programs
This post is not about learning syntax or basic programming. So if you don't know anything or just started programming I recommend you to just read a book or watch videos about any programming language related and filled your head with that until you become obsessed on your programming journey
Open up your dev environment then set your build setup. As for me I would be using Makefile, you could use anything at your disposal. What really matter here is the compiler argument, set it to be like this
CFLAGS = -Os -Wall -Wextra -std=c99 -s -nostdlib -fno-builtin
Use that if your project doesn't have any dependencies, yes I mean it you only can use system baked api rather libraries. For more information look at gnu cc page about this.
int main(int argc, char **argv);
`argc` and `argv` will
not work here so you need to create your own cmdline parser. Someone that
I respected a lot and I've never met have a blog about
this
`main` is not the real Entry Point of a program,
actually you can make anything to be Entry Point. But for a maintainability
you should use this.
// Windows
int WinMainCRTStartup(void); // Use this with -mwindows
int mainCRTStartup(void); // Use this with -mconsole
// Linux
int _start();
On Windows there's already defined interface for this, it's in
`-lkernel32` so you need link that library. but in
Linux it's different matter _start usually written in Assembly
_start: mov edi, [rsp] ; argc
lea rsi, [rsp+8] ; argv
call main
mov edi, eax
mov eax, 60 ; SYS_exit
syscall
You can change `main` to anything you like here,
but for easy compile on windows and linux you should use Windows entry point
above and add `extern WinMainCRTStartup` to the top
of the file
gcc -Os -Wall -Wextra -std=c99 -s -nostdlib -fno-builtin -o tiny\
tiny.c tiny.S -lkernel32
And now you have it, a teensy executable file with no purpose only amusement. It's cool tho, now you can expand it to whatever you liked. See my smoll repos for reference
rant'
>size doesn't matter cuz many pooters now came with big disk
Moore's law still affect pooters to this day, but software becomes more shittier each day. My point is software developer become ignorant about performance and the size of their slop.
So I learn Embedded Programming, went to college taking CompEng degree to become better developer or so I thought. College didn't teach me shit.
Here's what I learned in my self-taught journey
- Learn how to read book
- Read the manual or spec
- Learn how to google trickery shit
- Don't afraid to ask if you don't know smth
That's it folks, you just need learn it little by little and I'm sure You'll achieve what you wanted.