Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/chapter1/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,25 @@ To get setup:
- Run:

```sh
git clone <repo-link> # Clone to your machine
cd <repo-name> # Enter clone's directory
git remote add upstream <repo-link> # Create link to template called 'upstream'
git remote set-url --push upstream DISABLE # Disable pushing to template
git fetch upstream # Sync with 'upstream'
git merge upstream/main --allow-unrelated-histories # Merge 'upstream' main branch with your main
# Clone to your machine
git clone <repo-link>

# Enter clone's directory
cd <repo-name>

# Create link to template called 'upstream'
git remote add upstream https://github.com/MonashDeepNeuron/HPC-Training-Challenges.git

# Disable pushing to template
git remote set-url --push upstream DISABLE

# Sync with 'upstream'
git fetch upstream

# Merge 'upstream' main branch with your main
git merge upstream/main --allow-unrelated-histories

# Open repository in VSCode
code .
```

Expand Down Expand Up @@ -60,7 +73,7 @@ When you want to attempt a challenge it is good practice to create a branch. Thi
git branch <branch-name> # Create new branch
git checkout <branch-name> # Checkout to the new branch
# or
git checkout -b <branch-name # Checkout to a new branch
git checkout -b <branch-name> # Checkout to a new branch
```

For your training. I would recommend creating a new branch for every challenge you attempt and merging them with the `main` (default) branch once you are done. This allows you to make modifications to each of your attempts independent of each other as well as make it easier to resync with the template repository should anything change at its base. it also allows you to get some meaningful practice with Git which is one of the most used developer tools in the world.
Expand Down
16 changes: 13 additions & 3 deletions src/chapter2/vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ Sometimes you want data to be constant or immutable. This is data that does not
const int a = 4;
```

### Static Data

In C you can also allows you to create data that will exist for the entire lifetime of the program and is declared with the `static` keyword before the type initialiser. This kind of data is said to have static storage duration which means that it remains 'alive' or valid for the entire duration of the program and will not automatically get cleaned up when the it has left scope. This has some interesting implications but the most useful is its usage in function blocks. Static variables allow data to persist between function calls, meaning that if you invoke a function that owns a static variable; say an `int`, was left with the value `9` once the called had completed, if you were to recall the function and inspect the value the static variable it would still contain the value `9` at the start of the call. This allows you to keep data between function calls.

```c
static int a = 9;
```

There are other more advanced usages of `static` that allow you to control the linkage of different translation units (source and object files) but they are beyond the scope of this book.

## Operators

Operators are the most primitive way to manipulate data and variables in C. There are four major categories for operators these being arithmetic, bitwise, logical and assignment. Each operator is written in either infix (binary), prefix or prefix (unary) form. Most operators return the result of their evaluation meaning it can can be assigned to a new variable however, some modify the data in-place, this includes all assignment operators and the increment and decrement operators (which do both).
Expand Down Expand Up @@ -89,7 +99,7 @@ Bitwise operators are used to manipulate the individual bits of an integral type

| Operator | Name | Description | Example |
|:-----------------------:|:------------------:|:-----------------------------------------------------:|:-----------------------:|
| `~` | Compliment | Inverts the bits of a values | `~a` |
| `~` | Complement | Inverts the bits of a values | `~a` |
| `&` | And | Ands the bits of two values | `a & b` |
| <code>&vert;</code> | Or | Ors the bits of two values | <code>a &vert; b</code> |
| `^` | Exclusive Or (Xor) | Xors the bits of two values | `a ^ b` |
Expand All @@ -100,8 +110,8 @@ Bitwise operators are used to manipulate the individual bits of an integral type
>
> - Bitwise operators do not exist for floating point types.
> - Bits are lost from shift operators.
> - Left shift (`>>`) pads with zeros ie. adds a zero in the new empty position.
> - Right shift (`<<`) pads with the most significant bit ie. the new empty position is filled with the same value as the previous occupant.
> - Left shift (`<<`) pads with zeros ie. adds a zero in the new empty position.
> - Right shift (`>>`) pads with the most significant bit ie. the new empty position is filled with the same value as the previous occupant.
> - Left and right shifts are formally described respectively as: \\(a << b ≡ a * 2^{b} mod(2^{N})\\) and \\(a >> b ≡ \frac{a}{2^{b}} mod(2^{N})\\) where \\(N\\) is the numbers bits in the resulting value.

### Logical Operators
Expand Down