C - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

C

Description:

'The C language is like a carving knife: simple, sharp, and extremely ... char buf[BUFSIZ]; setbuf (stdout, buf); while ((c = getchar()) != EOF) putchar (c) ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 13
Provided by: BUG11
Category:
Tags: bufsiz

less

Transcript and Presenter's Notes

Title: C


1
C
  • Crash course in robot programming
  • 20.02.2007
  • Sizarta Sarshar

2
Next two hours
  • C Programming
  • The C reference
  • Traps and pitfalls
  • Eyebot Programming
  • RoBios software
  • Eyebot library
  • Code samples
  • Tigergutt

3
The C Programming Language
  • The C reference guide
  • web link
  • The operator precedence
  • web link

4
Traps 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
5
Traps and Pitfalls
  • The faults are grouped in
  • Lexical
  • Syntactic
  • Semantic pitfalls
  • Portability pitfalls
  • Linkage
  • Library functions
  • The preprocessor

6
Lexical 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
. . .
7
Semantic 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()
8
Library 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)
9
Eyebot 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

10
Eyebot 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.

11
Tigergutt
  • Web link

12
The End
Write a Comment
User Comments (0)
About PowerShow.com