UNIX Programming: Understanding the Environment, Makefiles, and C Compilers, Slides of Computer Programming

An overview of the unix programming environment, focusing on editors, c compilers, debuggers, and makefiles. It covers the basics of make, macros, target rules, and inference rules. Additionally, it discusses header files, macro definitions, command line arguments, and utilities in c. The document also touches upon some header file errors and conditional code in headers.

Typology: Slides

2012/2013

Uploaded on 04/29/2013

parmita
parmita 🇮🇳

4.7

(17)

183 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Week 1 Topics
Course outline and policies
UNIX programming environment
Editors
C compilers and debuggers
Makefiles
Review some features of C
Header files
Command line arguments
Utilities
Review some UNIX system calls
system, etc
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download UNIX Programming: Understanding the Environment, Makefiles, and C Compilers and more Slides Computer Programming in PDF only on Docsity!

Week 1 Topics

  • Course outline and policies
  • UNIX programming environment
    • Editors
    • C compilers and debuggers
    • Makefiles
  • Review some features of C
    • Header files
    • Command line arguments
    • Utilities
  • Review some UNIX system calls
    • system, etc

UNIX programming environment

  • Editors
  • C compilers
  • Debugger
  • Makefiles
    • make

Make

  • make [-f makefile][option] target
    • A tool to update files derived from other files
    • The default files for make are ./makefile, ./Makefile, ./s.makefile
    • Use the –f option to specify some other file
      • make –f makefile
    • The makefile has three components
      • Macros: define constants
      • Target rules: Specify how targets are made
      • Inference rules: Specify how targets can be made, implicitly. make will first check if a target rule applies, before using inference rules.

make ... continued

  • Macros:
    • String1 = string2.
      • Example CC=gcc CFLAG=-Wall –ansi –pedantic
  • Target rules:
    • Target : [prerequisite…]
    • command
    • command
      • Example a.out : myprog1.c myprog2.c myprog3.c $(CC) $(CFLAG) myprog1.c myprog2.c myprog3.c

makefile examples

  • See the example makefiles
    • makefile, makefile1, makefile
  • makefile1 will recompile only the modified files, instead of everything
  • makefile2 has inference rules
  • www.cs.fsu.edu/cgi-bin/man.cgi can be used to find more information

Review some features of C

  • Header files
  • Macros
  • Command line arguments
  • Utilities

Some header file errors

  • Improper header file use can cause problems
    • Try compiling example2.c
    • Including a header file multiple times may cause redefinition errors
    • Why does including stdio.h twice not cause any problem? - Look at /usr/include/stdio.h

Conditional Code in Headers

  • Preprocessor directives are used to prevent the body of a header file from being used multiple times. #ifndef MYHEADER #define MYHEADER /* the body of the header file */ #endif

Some useful functions

  • #include <stdio.h>
  • int sprintf(char *s, const char *format, ...);
  • int sscanf(const char *s, const char *format, ...);
  • How would these be used to get all the fields from the output of the shell command ps? - See example4.c.

Some Unix System Calls

  • You may use these in your first assignement
    • system
    • mkstemp

mkstemp

#include <stdlib.h>

int mkstemp(char *template)

  • template should end in XXXXXX
  • It replaces XXXXXX with unique file name, and returns an open file descriptor for a file available for reading and writing