Hacker News new | ask | show | jobs
by grafelic 2297 days ago
An interesting way IME to learn C, is to code for an old platform like the Amiga.

All the same best practices apply, but the underlying OS is more simple and the constraints, like missing floating point, forces you investigate many aspects of C.

You can use Bebbo's m68k cross compiler to compile for the platform: https://github.com/bebbo/amiga-gcc

No single source of truth for C best practices exist, but I can recommend using static analyzers like:

https://splint.org/

and

http://cppcheck.sourceforge.net/

to steer you in the right direction.

Also, compile your code with the following gcc options: -pedantic -std=<c99 or c89> -ggdb3 -O0 -Wall -Wextra -Wformat=2 -Wmissing-include-dirs -Winit-self -Wswitch-default -Wswitch-enum -Wunused-parameter -Wfloat-equal -Wundef -Wshadow -Wlarger-than-1000 -Wunsafe-loop-optimizations -Wbad-function-cast -Wcast-qual -Wcast-align -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Winvalid-pch -Wvolatile-register-var -Wstrict-aliasing=2 -Wstrict-overflow=2 -Wtraditional-conversion -Wwrite-strings

Not that they all necessarily always makes sense, but they will reveal weak points in your code.