E2 C language programming

Although OSOC aims to teach you how to design a processor chip, you will still frequently deal with software because processor chips are different from other types of chips. Therefore, to understand how to make programs run better, you first need to understand how they run on a processor.

C language is the best choice to help you to understand this problem, and considering that many of the students participating in "One Student One Chip" project do not have a computer science background, C is relatively easy to learn. You should be familiar with the following: recursion, pointers, linked lists, and be able to write a correct program on your own rather than relying on sample code you find on Google.

Learn C language through online websites

You should have already used the [Compiler Explorer][compiler explorer] online website to run C programs. Now you will systematically learn C language programming and complete some programming assignments through this online website.

You can choose the learning materials you want to study yourself, but please make sure you understand:

  • Basic Concepts of Programs
    • Programs and Programming Languages
    • Natural Languages and Formal Languages
    • Program Debugging
    • Compilers
  • Constants, Variables, and Expressions
    • Constants
    • Variables
    • Assignment
    • Expressions
    • Character Types and Character Encodings
  • Simple Functions
    • Mathematical Functions
    • User-Defined Functions
    • Formal and Actual Parameters
    • Global Variables, Local Variables, and Scope
  • Branching Statements
    • if Statements
    • if/else Statements
    • Boolean Algebra
    • switch Statements
  • Understanding Functions in Depth
    • return Statements
    • Incremental Development
    • Recursion
  • Loop Statements
    • while Statements
    • do/while Statements
    • for Statements
    • break and continue Statements
    • Nested Loops
    • goto Statements and Labels
  • Structures
    • Composite Types and Structures
    • Data Abstraction
    • Type Tags
    • Nested Structures
  • Arrays
    • Basic Concepts of Arrays
    • Strings
    • Multidimensional Arrays
  • Coding Style
    • Indentation and Whitespace
    • Comments
    • Naming Identifiers
    • Functions
    • The indent Tool
  • Sorting and Searching
    • The Concept of Algorithms
    • Insertion Sort
    • Analysis of Algorithmic Time Complexity
    • Merge Sort
    • Linear Search
    • Binary Search
  • Stacks and Queues
    • The Concept of Data Structures
    • Stacks
    • Depth-First Search
    • Queues and Breadth-First Search
    • Circular Queues
  • Representation of Numbers in Computers
    • Why Computers Use Binary Notation
    • Converting Between Different Number Bases
    • Integer Addition and Subtraction
      • Sign and Magnitude Representation
      • 1's Complement Representation
      • 2's Complement Representation
      • Signed and Unsigned Numbers
    • Floating-Point Numbers
  • Data Types in Detail
    • Integer Types
    • Floating-Point Types
    • Type Conversions
      • Integer Promotion
      • Usual Arithmetic Conversion
      • Type Conversions Caused by Assignment
      • Explicit Type Conversions
      • How the Compiler Handles Type Conversions
  • Operators in Detail
    • Bitwise Operations
      • Bitwise AND, OR, XOR, and NOT Operations
      • Shift Operations
      • Masks
      • Some Properties of XOR Operations
    • Other Operators
      • Compound Assignment Operators
      • The Conditional Operator
      • The Comma Operator
      • The sizeof Operator and typedef Type Declarations
    • Side Effects and Sequence Points
  • Preprocessing
    • The Preprocessing Steps
    • Macro Definitions
      • Function-Like Macro Definitions
      • Inline Functions
      • The # and ## Operators and Variadic Arguments
      • The Steps of Macro Expansion
    • Conditional Preprocessing Directives
    • Other Preprocessing Features
  • Pointers
    • Basic Concepts of Pointers
    • Parameters and Return Values of Pointer Types
    • Pointers and Arrays
    • Pointers and the const Qualifier
    • Pointers and Structures
    • Pointers to Pointers and Arrays of Pointers
    • Pointers to Arrays and Multidimensional Arrays
    • Function Types and Function Pointer Types
    • Incomplete Types and Complex Declarations
  • Function Interfaces
    • Prerequisites for This Chapter
      • strcpy and strncpy
      • malloc and free
    • Input Parameters and Output Parameters
    • Double-Pointer Parameters
    • Cases Where the Return Value Is a Pointer
    • Callback Functions
    • Variadic Arguments
  • String Manipulation Functions
    • Initializing Strings
    • Getting the Length of a String
    • Copying Strings
    • Concatenating Strings
    • Comparing Strings
    • Searching Strings
    • Splitting Strings
  • Standard I/O Library Functions
    • Basic Concepts of Files
    • fopen/fclose
    • stdin/stdout/stderr
    • errno and the perror Function
    • Byte-Oriented I/O Functions
    • Functions for Operating on the Read/Write Position
    • String-Oriented I/O Functions
    • Record-Oriented I/O Functions
    • Formatted I/O Functions
    • I/O Buffers in the C Standard Library
  • Linked Lists
    • Singly Linked Lists
    • Doubly Linked Lists
    • Static Linked Lists

If you don't mind using a translation tool, you can learn [One-stop Learning for Linux C Programming][linux c] Chapters 1-9, Chapters 11-16, Chapter 21, Chapters 23-25, and Chapter 26, Section 1 (i.e., ‘Linked Lists’). You need to complete all the exercises and test your programs in Compiler Explorer to see if it is correct. It fully covers all the requirements of this part.

In addition, after running the program correctly, you need to save the corresponding program code locally. On the one hand, you can keep these programs as your assignments. On the other hand, after installing Linux, we will ask you to run some of the code again.

If you are confident in your C language skills and can independently write a linked list program and debug it correctly without referring to other code, you can skip this part of the course. If you have not fully learned C language programming, or have forgotten most of it, we strongly advise you not to skip this part of the course.

More recommended materials for learning C

::::[compiler explorer]: https://godbolt.org/ [linux c]: http://akaedu.github.io/book/

zhr