C language

From ScienceZero
Revision as of 00:20, 23 January 2011 by Bjoern (Talk | contribs) (volatile)

Jump to: navigation, search

Things to remember about the C language if you want to keep sane

Declarations

#define

volatile

The volatile keyword tells the compiler that the dollowing object is subject to sudden change in a way that is not described in the source code. For example a RS-232 data register that receive data from the outside. Volatile forces the compiler to generate the code that access the memory location each time instead of cache it in a register. Can be applied to any declaration.

Symptoms of missing volatile statements:

  • Code fails when you enable compiler optimizations
  • Code fails when interrupts or DMA/Hardware peripherials are enabled

extern

static

const

Read only. Can be applied to any declaration.

const volatile unsigned long int base_address = 0xFFFF;

Loop constructs

for() direction and signed while do while


switch(var)
{
	case 0:
	//code
	break;
}

if else

& | ^ ~ >> (signed or not?) <<

&& || ==

!= > < >= <=

+= -=

  • =

/= >>= <<=


Type specifiers

Data types

  • char
  • long
  • long long
  • float
  • double
  • short
  • int

Other

  • void
  • signed
  • unsigned

type casting subroutines void return global vs local


pointers

& (unsigned int *)

arrays multiple dimensions array pointers, 1d, 2d string, terminating character /n /r /t escape characters vs ""

character and on what type of lines is belongs on


include files "file" <file> .c .h included libraries