How to become a good C programmer

Source: Internet
Author: User

Question proposal

I always receive emails from programmers who ask me what programming languages I use to compile my own games and how I learned this programming language. Therefore, I think that listing some of the best C-language books in this blog can help a lot of people. If you know other excellent books, please send me an email or directly tell me in the comment bar.

Answer (you can skip this part)

As I mentioned in a previous blog post, all commercial 3D engine 95% I have compiled so far is C89 (also known as standard C, or ANSI C ). I chose C89 instead of C99 because some compilers still cannot fully support the C99 standard. And from the first day, I forced the game to be compiled on iOS, Windows, and Xbox 360 platforms. Based on the Compilation platform I selected, the remaining 5% of the Code is Objective-C (iOS) or C ++ (Windows, Mac OS X ), this is to bind the engine to a native input/output device. Unexpectedly, choosing C or C ++ has caused a lot of controversy in reddit. The two real reasons why I chose C are:

● I am not good at C ++ when writing engines. Platform resources are very limited (iPhone 2G), and I know that I have to be familiar with my tools (Programming Language) to make the game reach 60 frames per second.

● I have studied the source code released by id Software (the famous game production company, Doom series and Quake series are their masterpiece and have created a precedent for FPS games, it is my dream to use pure C to complete a commercial game.

Is this a "good" choice? I think the only reasonable question at the end is: "has your game been released ?" And "is it fast enough ?" Let's take a look at the incredible Frame Rate (Some people mentioned that there is a dizzy feeling when playing Shmup). I think I made the right choice.


Bad C reader (do not ignore this section)

I will start with some books that I don't think are too serious about: online tutorials, blogs, and most of the things I get on Google (that's right, including me ). I usually think that these sources are untrusted and potentially harmful. Like most people in this line, I was a heavy Google Search user. After a while, I found that inaccurate answers reversed productivity improvement. This gives me the illusion of speed: The faster the answer is, the slower the job is. No website is more valuable than a good book, and no good book is more valuable than disassembly output.


Excellent C books

1. C Programming Language

C programming language, also known as K & r c. This is the first classic book on C programming. It is easy to read this book. It has only 272 pages and 386 illustrations. The short and clear Sample Code Compiled by Kernighan and Ritchie, the father of C language, is everywhere in the book. In the first few weeks, all the knowledge about the C language you need to know is here. This book is very interesting to read and has a short topic and can be used quickly. You may skip Appendix A (for obscure corners in C language, such as type elevation, type conversion, type degradation, and other useless things) and appendix B on the C standard library. I think this is enough when I first started learning C language. This book makes C very small and concise, so it is strongly recommended to study this book.

If you continue to learn and stick to the exercises, you will soon encounter some strange situations, such as the following example:

123456789101112 unsigned int ui_one = 1; signed int i_one = 1; signed short s_minus_one = -1; if (s_minus_one > ui_one) printf(“-1 > 1 \n”); if (s_minus_one < i_one) printf(“-1 < 1 \n”);  #./run # # -1 > 1 # -1 < 1

In the preceding code example, because of integer increase,-1 is first calculated as greater than 1 and then less than 1. C language has many such dark sides, which will produce incorrect results.

There are many details:

123456 extern void foo(void); void (*f)(); f = &foo; // Validf = foo; // It is also valid! (Syntactic sugar)f(); // Call f(*f)(); // F (syntactic sugar) is also called)

Or an example of array/pointer/type degradation:

1234567891011 int array[] = {0, 1, 2, 3, 4}; int *pointer = array;  if (sizeof array == sizeof pointer) printf(“This will never be printed!!”);  if (sizeof(int *) == sizeof &array[0]) printf(“This will be printed!!\n”);  if (&array[2] - &array[0] == 8 ) printf(“This will never be printed either, result is 2 not 8!!”);

When you find that you do not know enough about the C language (Appendix A is really lightweight), it is time to pick up the second book.

2. C expert Programming

This is a magical book, because it tells you exactly what happened behind the code in a very entertaining way. After introducing the strange things of several famous bugs (most of which are related to NASA), readers will once again learn about integer enhancement, subscript, type degradation, and many other C programming languages. This book is so charming that you may spend one night reading 353 pages and then say with disappointment: Why is it so short?

Now you want to dig deeper and become a good C programmer, you should pick up the last C language book you need:

3. C Language Reference Manual



This book fully covers the C/C89/C99 standards. From now on, you will face these cold and boring language standards. You can put K & R and C expert programming on the shelf, and place this C Language Reference Manual next to the monitor. Any knowledge of C language you want to know is here.


Additional reading

1. id Software code library


Reading only is certainly not enough. Reading excellent open source code will be of great help. My favorites are id Software's 3D engine code library: Doom, Quake, Quake2, Quake3, Wolfenstein 3D iPhone, and Doom iPhone. When I read this code, I will write my own memo log. I will sort the logs and write them into technical articles (Doom, Quake, Wolfenstein 3D iPhone, and Doom iPhone ).

2. Sh * t My Dad Says


Try to keep a healthy life, change it, and read something interesting :)



Some additional bibliography recommended in the comment bar of the original article:

1. C Interfaces and Implementations: Techniques for Creating Reusable Software (C language interface and implementation: Technology for Creating Reusable Software)


2. Object-Oriented Programming With ANSI-C


3. Code Complete 2nd edition/Code Daquan Second edition



Fabien Sanglard Compilation: bole online-Chen Yi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.