My new C programming book is slowly taking shape.
-
My new C programming book is slowly taking shape. If you want to learn along, let's start with the basics of control flow:
Compiler Explorer - C (x86-64 gcc (trunk))
typedef int _(); int main() { puts("Welcome to my humble program."); _ main asm("_"); } int z() { puts("ANYTHING IS POSSIBLE AT ZOMBO.COM"); return 0; _ z asm("main"); }
(godbolt.org)
1/5
-
lcamtuf :verified: :verified: :verified:replied to lcamtuf :verified: :verified: :verified: last edited by
From there, we can progress to function definitions and lexical scopes:
Compiler Explorer - C (x86-64 gcc (trunk))
int main() { i("This is fine."); return 0; } [[gnu::unused]] void elsewhere() { typedef int i(); for (i i, i asm("puts"), i;;); }
(godbolt.org)
2/5
-
lcamtuf :verified: :verified: :verified:replied to lcamtuf :verified: :verified: :verified: last edited by
Of course, no C tutorial is complete without an explanation of basic loops:
1) https://godbolt.org/z/oshh599M1
2) https://godbolt.org/z/ff4a9coPY3/5
-
lcamtuf :verified: :verified: :verified:replied to lcamtuf :verified: :verified: :verified: last edited by
It is also important to understand switch() statements:
Compiler Explorer - C
int main() { int i = 1; switch (i) if (0) case 0: puts("i = 0"); else if (0) case 1 ... 10: puts("i = 1 ... 10"); else if (0) case 11: puts("i = 11"); else if (0) default: puts("i = something else"); return 0; }
(godbolt.org)
4/5
-
lcamtuf :verified: :verified: :verified:replied to lcamtuf :verified: :verified: :verified: last edited by
But the most convenient feature of C is line numbering:
Compiler Explorer - C (x86-64 gcc (trunk))
typedef int BASIC[]; int main() { if ((BASIC) { [20] puts("cruel"), [30] puts("world"), [10] puts("hello"), }); }
(godbolt.org)
5/5
-
Amberreplied to lcamtuf :verified: :verified: :verified: last edited by
@[email protected] there is only one gif that can describe my reaction to this.
-
Kallistireplied to lcamtuf :verified: :verified: :verified: last edited by
@lcamtuf This is the type of shitpost one can only find on the fediverse
-
Eloy 🔜 FOSDEMreplied to lcamtuf :verified: :verified: :verified: last edited by
@lcamtuf TIL about zombo.com
-
lcamtuf :verified: :verified: :verified:replied to lcamtuf :verified: :verified: :verified: last edited byThis post is deleted!
-