Saltar al contenido ForoHackers

C: start here

C
#543 · Ophuscado · · Denunciar

C is a small, fast, low-level language that sits just above the hardware. Operating systems, databases, language runtimes and firmware are written in it, and nearly every other language can call into it. It gives you direct control of memory and almost no safety net, which makes it a superb teacher and an easy way to write dangerous bugs.

Key concepts

  • Pointers and arrays: a pointer is an address; arrays decay to pointers and indexing is pointer arithmetic.
  • Manual memory: you allocate and free heap memory yourself, and the stack holds locals.
  • Types and layout: integer sizes, signedness, structs, padding and alignment.
  • Undefined behaviour: overflowing a signed integer or reading past an array is not an error but a licence for the compiler to do anything.
  • Preprocessor and headers: text inclusion and macros before compilation proper.
  • Separate compilation: source files become object files that the linker joins.

Vocabulary

  • Dangling pointer: a pointer to memory already freed or out of scope.
  • Buffer overflow: writing past the end of an array.
  • Translation unit: one source file after the preprocessor has run.
  • Standard library: the portable functions the language standard guarantees, such as string and file handling.

What to study, in order

  1. Write small programs with variables, loops, functions and arrays, compiled with all warnings on.
  2. Master pointers: strings, pointer arithmetic, pointers to pointers and to functions.
  3. Use malloc and free for a dynamic array and a linked list, then check them with a memory-error tool.
  4. Split a project over several files with headers and a build tool.
  5. Implement a hash table and a tokenizer from scratch.
  6. Read the language standard's section on undefined behaviour and learn the sanitisers.

Related tags

#assembly #memory-management #secure-coding #build-systems

Inicia sesión o únete para responder.