Thinking in C and *nix (CSC 295/282 2014S) : Outlines

Outline 12: Miscellaneous C Programming Issues


Held: Thursday, 24 April 2014

Back to Outline 11 - Debugging with GDB. On to Outline 13 - Variadic Functions.

Summary

We consider a variety of smaller issues that might make you a better C programmer.

Related Pages

Overview

Administrivia

assert - simple program checking

  i = 5;
  // I assume i is 5
  foo (i);
  // I assume i is still 5, since C is a pass-by-value language

Memory Issues in C Programs

Valgrind: Tracking memory issues

Sorting

/**
* Sort an array of strings alphabetically.
 */
int strings_sort (int n, char *strings[])
/**
* Sort an array of strings using comparator.
 */
int strings_sort (int n, char *strings[], "*something-that-compares-strings*" compare)

Function Pointers

int strings_sort (int n, char *strings[],
                  int (*compare)(char *str1, char *str2));
int (*binary_integer_function)(int x1, int x2);
typedef int (*StringComparator)(char *str1, char *str2);
int strings_sort (int n, char *strings[], StringComparator compare);
(*compare)(str1, str2)
compare (str1, str2);

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.