Home * Programming * Languages * C

C is a pragmatical, general purpose, block structured, procedural, imperative programming language. C was developed in 1972 by Dennis Ritchie at the Bell Laboratories. It was first intended as a system programming language for the Unix operating system, but has spread to many other platforms and application programming as well. C and its derivations are likely the most often used languages so far for computer chess programming.

Due to explicit pointers (address of a variable or function), C can be considered as a high level assembly language, but has some weak spots in its initial design and implementation, which are addressed in

Data

Data Types

Primitive Data Types

To be aware of the scalar 64-bit origin of bitboards in computer chess, we use so far a type defined unsigned integer U64 in our C and C++ source snippets. The macro C64 will append a suffix to 64-bit constants as required by some compilers:
typedef unsigned __int64 U64;    // for the old microsoft compilers
typedef unsigned long long  U64; // supported by MSC 13.00+ and C99
#define C64(constantU64) constantU64##ULL

Pointer

Array


Struct

A structure in C refers to Object composition to encapsulate related scalar datatypes inside one structured item. The size of the structure is the sum of its element sizes. To access the structure elements the dot-operator separates the element from the variable or reference. Pointers require arrow operator.
struct MOVE
{
   char from;
   char to;
};
 
...
MOVE m, a, *b;
m.from = square;
...
if ( a.from == b->to )

Bitfield

So called Bitfields might be implemented as structure where integer members are declared with explicit bit length specifier from 1 .. 31. However due to portability issues of various C-compilers and platforms concerning bit ordering, padding and eventually the sign, most programmer rely on explicit bitfields to composite and extract sub-items by shift and masks, i.e. in encoding moves.

Union


Variables

Variables are either stored in various memory areas or kept inside processor registers.

Globals

On the Stack

On the Heap

Register


Instructions

Operations

Arithmetical

Bitwise boolean

Relational

Logical

Functions

Expressions


Control Flow


Goto


If else


Switch case


Function Pointer


For


While


Do while


Preprocessor


Portabilty

Twos' Complement

sizeof

shift

Endianness

Main article Endianness

Libraries


C and C++ Compiler

A C-Compiler is used to translate the source program, usually ascii-text files with the extension .C, to so called object files, containing machine instructions. A linker binds all the object files together with libraries containing external functions (and data) to build an executable program.

Books


Publications


Forum Posts

1999

2000 ...

2005 ...

2010 ...

2015 ...


External Links


References

  1. ^ LLVM from Wikipedia
  2. ^ Edsger Dijkstra (1968). Go To Statement Considered Harmful. Communications of the ACM, Vol. 11, No. 3, pdf
  3. ^ William A. Wulf (1971). Programming Without the GOTO. IFIP, Ljubljana, Yugoslavia, August 1971
  4. ^ William A. Wulf (1972). A Case Against the GOTO. Proceedings of the ACM National Conference, Boston, August 197
  5. ^ Donald Knuth (1974). Structured Programming with go to Statements. ACM Computing Surveys, Vol. 6, No. 4, pdf
  6. ^ Ward Douglas Maurer (1996). Attitudes toward the go-to statement (or, hydrogen considered harmful). Computers & Education, Vol. 26, No. 4
  7. ^ Coding Horror: I'd Consider That Harmful, Too by Jeff Atwood, October 25, 2007
  8. ^ Steve McConnell (1993). Code Complete: A Practical Handbook of Software Construction. Microsoft Press

Up one Level