Difference between revisions of "C language"

From ScienceZero
Jump to: navigation, search
(Type specifiers)
(Type specifiers)
Line 80: Line 80:
 
Memory alignement in bits is word length or 32 whichever is smallest
 
Memory alignement in bits is word length or 32 whichever is smallest
  
*char
 
*short   
 
*int     
 
*long
 
*long long
 
*float
 
*double   
 
 
=== Other ===
 
=== Other ===
 
*void
 
*void

Revision as of 01:41, 23 January 2011

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

The stack

Symptoms:

  • The program counter seems to jump around at random
  • Corrupted variables and data.

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 (ARM C and C++)

  • char 8 bits
  • short 16 bits
  • int 32 bits
  • long 32 bits
  • long long 64 bits (The low word of a long long is at the low address in little-endian mode, and at the high address in big-endian mode.)
  • float 32 bits
  • double 64 bits
  • long double 64 bits
  • All pointers 32 bits
  • bool (C++ only) 32 bits

Memory alignement in bits is word length or 32 whichever is smallest

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