Title: C
1C
- Crash course in robot programming
- 20.02.2007
- Sizarta Sarshar
2Next two hours
- C Programming
- The C reference
- Traps and pitfalls
- Eyebot Programming
- RoBios software
- Eyebot library
- Code samples
- Tigergutt
3The C Programming Language
- The C reference guide
- web link
- The operator precedence
- web link
4Traps and Pitfalls
C makes it easy to shoot yourself in the
foot - B. Stroustrup
The C language is like a carving knife
simple, sharp, and extremely useful in skilled
hands. Like any sharp tool, C can injure people
who do not know how to handle it - A. Koenig
5Traps and Pitfalls
- The faults are grouped in
- Lexical
- Syntactic
- Semantic pitfalls
- Portability pitfalls
- Linkage
- Library functions
- The preprocessor
6Lexical and syntactic faults
y x/p / p points at the divisor
/ a-1 a -1 while (cgetc(in) ! EOF)
while ((cgetc(in)) ! EOF) putc(c,out)
putc(c,out) switch (color) case 1
printf ("red") case 2 printf ("yellow")
case 3 printf ("blue") case SUBTRACT
opnd2 -opnd2 / no break / case ADD
. . .
7Semantic pitfalls
i 0 while (i lt n) // There
is no guarantee that the adress of yi yi
xi // will be evaluated before i is
incremented i 0 while (i lt n) yi
xi i double s double s,
sqrt() s sqrt (2) s sqrt(2.0) printf
("g\n", s) printf ("g\n", s) if (a b
lt 0) if ((int) ((unsigned) a (unsigned)
b) lt 0) complain() complain()
8Library functions
include ltstdio.hgt main() char c
while ((c getchar()) ! EOF) putchar
(c) include ltstdio.hgt main() int c
char bufBUFSIZ setbuf (stdout, buf)
while ((c getchar()) ! EOF)
putchar (c)
9Eyebot Programming
- RoBios software
- Download and install
- Compiler
- Use the shell script gcc68 for compiling a C
program. It is accessed from the RoBios console.
Compiling only - gcc68 -c filename.c
- Compiling and generating an output file for
download to the Eyebot controller - gcc68 filename.c
- The result is stored in a file named a.out. In
order to use custom output names you may use the
following - gcc68 filename.c -o filename.out
- If the code makes use of the math library, add
the extension -lm. - gcc68 filename.c -o filename.out -lm
10Eyebot Programming
- Send the file from the host (PC) using RoBios
console transhex - transhex filename.out
- In order to start up a program automatically at
startup, call your downloaded program startup.hex
and save it in a ROM slot.
11Tigergutt
12The End