Upgrade to Pro — share decks privately, control downloads, hide ads and more …

C Programming on Linux

C Programming on Linux

CPSC 317 Tutorial, March 15th 2013.

Avatar for Kalan MacRow

Kalan MacRow

March 15, 2013
Tweet

More Decks by Kalan MacRow

Other Decks in Education

Transcript

  1. Agenda • Housekeeping • Why C? • Pointers (and Strings)

    • Beej’s Guide • Working on A3 2
  2. Housekeeping • A1 grades are out • A2 demos this

    week and next • A3 to be released very soon • Today we’re prepping for A3 3
  3. Why C? • Still systems language of choice! • Low-level

    access • Portability, speed, size • Terse syntax over assembly • No runtime required • Long, proud history in OS development 4
  4. Pointers • Your process has an address space • You

    access memory by address • A pointer is simply an address 5
  5. Pointers char *ptr = an address ... ptr vs. *ptr

    An address is represented by an integer type 6
  6. Strings • In C, a string is an array of

    chars • char  s1[128]; • char  *s2  =  (char*)malloc(128); • s1, s2 are both pointers!   9
  7. Strings • There’s no s1.length() • Instead: NULL byte at

    the end • strlen(s1) counts until it finds a “\0” • Don’t use string functions on binary data! 10
  8. Beej’s Guide • Google it • We’re doing network programming

    • Lots of examples in C! http://beej.us/guide/bgnet/ 11
  9. Working on A3 • Need to compile, debug, test on

    linux • Specifically: our ugrad linux machines $  ssh  kalanwm@remote.ugrad.cs.ubc.ca Last  login:  Fri  Mar  15  07:58:08  2013  from  sonora.cs.ubc.ca Have  a  lot  of  fun... deas:~>  cat  /etc/*-­‐release NAME=openSUSE VERSION  =  12.1  (Asparagus) VERSION_ID="12.1" PRETTY_NAME="openSUSE  12.1  (Asparagus)  (x86_64)" ID=opensuse openSUSE  12.1  (x86_64) VERSION  =  12.1 CODENAME  =  Asparagus 12
  10. Working on A3 • Linux: mount remote.ugrad.cs.ubc.ca • OSX: Fuse

    for OSX + Macfusion or ssh • Windows: Putty + Xmanager or Xming • Don’t use Windows ports (cygwin)! Suggestions 13
  11. Working on A • Platform matters! • Compilers produce different

    code • Timing issues, library versions = headaches • Build and test your code on ugrad servers! • Consider DDD + GDB for debugging 14
  12. Working on A3 • More about A3 • Sample dev

    environment (OSX) • Network programming in C • Debugging C programs 15