From 8bc9cef75f08c60ee6206dbf6b422e55912dacf8 Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Thu, 4 Aug 2022 11:16:03 +1200 Subject: [PATCH] vault backup: 2022-08-04 11:16:03 --- content/notes/08-intro-to-c.md | 48 +++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/content/notes/08-intro-to-c.md b/content/notes/08-intro-to-c.md index 2b498f3ba..2ca0e76a9 100644 --- a/content/notes/08-intro-to-c.md +++ b/content/notes/08-intro-to-c.md @@ -9,9 +9,55 @@ tags: Developed 1972 for Unix - widely used + - compilers esxist for most OSs and architectiures - diverse use + - OSs, device drivers, protocol stacks + - less so for application software - low level -- not Object Or + - language features map to CPU features +- not Object Oriented + - no classes etc > “C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support. Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant C program written with portability in mind can be compiled for a wide variety of computer platforms and operating systems with few changes to its source code.” - wikipedia +``` +#include + +int main(int argc, const char *argv[]) +{ + puts("Hello World"); + return 0; +} +``` + +# \#include +java uses .class files, C uses .c and .h +- .c for implementation +- .h for extern declarations (similar to `public`) + +java uses `import`, C uses `#include` + +``` +#include +#include "myfile.h" +``` + +- `#include` literally includes the file with the given name right there into the file eing compiled +- in `hello_world.c` we include `stdio.h` so we can call `puts()` + +# Routines +``` +int main(int argc, const char *argv[]) +{ + +} +``` + +routines can be scoped to just the source code file +- `statis int eleven(void` + +routines must be declared bfore being used +- `extern int eleven(void)` + +# If statements +