Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Reading & exercises

(2.5 h) reading with exercises scattered between the text + (20 min) self-review exercises

Read the chapter and do the exercises in Chapter 2 of the book:

Coding environment continued

(30-60 min)

Compiler installation

We will use the Clang compiler[2].

Open a terminal and prompt:

Windows
MacOS
winget install martinstorsjo.llvm-mingw.ucrt

Compiler test

In your terminal, type:

clang

You should see a message similar as follows:

clang-XX: error: no input files

Extensions for the editor

In your terminal run[5]:

codium --install-extension GitHub.vscode-pull-request-github --install-extension llvm-vs-code-extensions.vscode-clangd --install-extension vadimcn.vscode-lldb

Git installation

We will use Git to communicate with the repositories on GitHub.

Windows
MacOS

Open a terminal and run:

winget install git.git

After installation, set your name. Use the mail address you used for GitHub.[6].

git config --global user.name "YOUR NAME"

Then your email:

git config --global user.email "YOUR_EMAIL"

Folder structure for the semester

Every project, will have its own folder and repository, e.g., repository1 and repository2. Based on this, my recommended directory structure is:

📁 your home folder, e.g., /Users/u/
├── 📁 Desktop
    ├── 📁 uni
        ├── 📁 26WS
            ├── 📁 cprog
                ├── 📁 code
                    ├── 📁 repository1
                    ├── 📁 repository2
                    ├── 📁 ...

You can create this structure using the following command in terminal:

Windows
MacOS & Linux
mkdir Desktop\uni\26WS\cprog\code

Running programs in the editor

  1. Start the editor.

  2. Open a terminal using the menu Terminal → New Terminal or CtrlShift`:

  3. The following command will change your directory to your code folder and clone the template repository into your code folder. Change the path to your code folder if you have a different structure.

    In the terminal, change your directory to the code folder:

    cd Desktop/uni/26WS/cprog/code

    And then copy the template repository into your code folder, called clone:

    git clone https://github.com/dtucprog/c-template-multi-main

    After cloning, you should see:

  4. In our editor, opening a project means opening the folder containing the projects files. These are in our case repository1, repository2, and not code folder.

    Open the folder that we cloned with git in the editor using File -> Open Folder:

  5. We trust each other, so click Manage

  6. Click Add Folder instead of Trust to trust the whole code folder[7]:

    Select the code folder and click Trust Folder. You should see:

    Close Workspace Trust window.

  7. On the left activity bar, click griddy-icons:files Explorer and click the folder src-> hello.*.

  8. We will now build and run the code using the debugger. Press F5 or Run -> Start Debugging. You should see:

    If you don’t see the emoji on Windows, refer here: Configuring PowerShell for rendering special symbols.

  9. You can also try a program with input. Click the file pi-estimator.* and run it.

The assignments will have their own repository, which you will clone into your code folder. We will practice this in the next lecture.

🏆 Congratulations!

Footnotes
  1. Because we will add additional repositories to the code folder.

  2. We use clang instead of the other popular gcc compiler, because clang’s error messages are more helpful for beginners.

  3. You can also use winget to uninstall the package, but we made the experience that some packages which were installed with administrator rights fail to be uninstalled when you try with winget on a user terminal.

    winget remove "LLVM MinGW (UCRT runtime)"
  4. An alternative tutorial with screenshots is here: https://www.wikihow.com/Change-the-PATH-Environment-Variable-on-Windows

  5. These are for convenient GitHub authentication, code completion and debugging, respectively.

  6. Some microprocessors have destructive read, e.g., in their timers.