GregDavidson / C-By-Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C By Example

C By Example

Copyright and License

A League of Extraordinary Learners curriculum!

The materials in this course may be used under the conditions of the license.

tl/dr

  1. Set up an environment for editing and running C Programs
    • See Setting up a C Programming Environment below
  2. Study each entry listed in GUIDE.org in the given order
  3. If it’s a program, run it, modify it, try variations!
  4. Try any suggested experiments. Ignore nothing!

Forward

What does this course cover?

This course is intended to present the essence of the C Programming Language as it existed after it became an ANSI Standard in 1989. By that time C had proven itself to be a remarkably powerful language for both systems and application programming, being the major language used to write the Unix Operating System including kernel, device drivers, system services, utilities, the Unix Programmers Workbench, a large number of applications and more. C was respected as much for its simplicity as for its power. The first ANSI C Standard provided a reference base for the Language that retained the elegance of Classic C with a few modernizations. While later versions of ANSI C and ISO C have added to the language, the original standard is the most elegant.

What are the goals of this course?

The goals of this course are to give the diligent reader a strong intuitive grounding in the essence of the C Programming Language, suitable for

  1. writing new C programs
  2. understanding and perhaps modifying existing C programs
  3. understanding the low-level fundamentals of programming
  4. continuing on to learn Modern C, Modern C++ or other languages

It is worth noting that the first goal of writing new C programs is much easier than the second goal of understanding and modifying existing programs.

C has several competitors in its niche, including C++ and Rust. These other languages are much more complex than C and tend to obscure what is going on at the level where the programmer’s code connects with the physical machine. C’s simplicity can be a boon to anyone who wants to understand what’s going on when they run programs written in any language. This understanding is critical to writing code which uses the machine’s resources efficiently, e.g. maximizing speed and/or minimizing the use of memory, IO bandwidth, energy, etc.

All of these goals are facilitated by starting with this earlier, simpler version of the C Programming Language.

How can you achive these goals for yourself?

To maximize your success with this course, you should

  • Set up a C Programming Environment on Your Machine
    • or you could use an online environment
    • see Setting up a C Programming Environment below
  • Spend some time with each file in the GUIDE.org in the given order
  • Be sure that you understand the function of each element
  • Compile and run each program
  • Try some modifications, exploring other possibilities
  • Carry out any suggested exercises

Setting up a C Programming Environment

At a minimum, a C Programming Environment should provide

  • a way to view and edit C source code
    • which are just text files ending in .c and .h
  • a way to compile, link and run your programs
    • compiling and linking may be transparent for simple programs
    • explicit use of linkers or project files required for programs which
      • use non-standard libraries
      • consist of multiple .c files

You’ll want an online debugger which allows you to

  • Set breakpoints and control execution
  • Inspect data structures in memory

There are many, many ways to set up a C Programming Environment

  • It depends on your operating system
  • It depends on your taste

If you want to postpone this decision, you can use a free online enviroment such as

Many modern development environments support programming in a variety of languages. If you’ve already been programming in some other language, you may find that it already supports C or that it will if you download a few free components.

NOTE: You can save a lot of time by either cloning this repository or downloading an archive in tar format so that you’ll have all of these files handy on your system. Github has t

C Programming on a Microsoft Windows system

Many people use https://visualstudio.microsoft.com/

  • Search for a tutorial on how to get started!

C Programming on a GNU Linux system

Consult your documentation for how to install the usual programming environment

  • If you don’t yet have a favorite editor, try nano
  • Experts tend to prefer vim or emacs but don’t learn them now!

Prefer running gcc and make from the shell - probably bash - rather than using a GUI. In this example, the shell types a prompt, e.g. $ and you type the rest:

$ nano hello.c 
$ gcc -o hello hello.c
$ ./hello

What format is this text in?

We are all hoping for a simple, standard, portable, widely used, network transparent, multi-media, presentation neutral hypertext system which allows readers to store their paths through it (this should be done by their presentation client) and to annotate and modify their view of the system. Unfortunately, despite the clearly expressed visions of people like Vanevar Bush and Ted Nelson, we are still lacking such a system. At the current time, the World Wide Web seems to come closest to these ideas.

At the current time the course is using a variety of text formats which can be automatically translated into other popular formats. One or more filename suffixes indicate the format used:

SuffixFormat
cStandard C
hStandard C
meroff me macros
orgOrgMode markup
eqnroff equation markup
picroff picture markup
tblroff table markup

How can I make improvements if I shouldn’t “lose information”?

Please add to this text, especially more examples. A great way to improve the text is by adding alternative branches for specialized topics. Of course you are free to make destructive changes of the text and programs, and I hope that when you do so your goal is to improve their clarity and that you will use a revision control system, such as RCS, to retain the previous versions, and pass those along when you distribute this text.

Best current practice is to include a link to a repository with the full history of this project. The current official repository is https://github.com/GregDavidson/C-By-Example

About

License:Creative Commons Attribution Share Alike 4.0 International


Languages

Language:C 99.4%Language:Shell 0.4%Language:Makefile 0.2%