Quick Guides CSUB Computer Science Department
ANSI C Programming on CS Machines
Frequently Encountered Problems

Core Dumps:

If you use CTRL-\ to force a core dump (which one can look at with 
gdb, for example) this will not work on helios (Solaris) unless you 
change the ulimit for core dump as follows:

ulimit -a               # list all limits
ulimit -c unlimited     # change to unlimited core dumps
{run program which locks up}
CTRL-\                  # send SIGQUIT
gdb program core        # find out where program is

Makefile: The dependencies in a makefile must be preceeded by TABS not SPACES. If you cut and paste to create a Makefile from windows the tabs will be turned into spaces and the Makefile will not run.

Recursion: In a recursive call you will get a core dump if you attempt to pass an argument which is postdecremented, e.g. index++ You must pass a predecremented argument; e.g. ++index, or index + 1.

make 2> out.txt will send the output of stderr to 'out.txt' for your review.

typedef enum boolean_tag { FALSE, TRUE } Boolean_type; will give a compilation error in Digital C because FALSE and TRUE are already defined as enumerated types where FALSE=0 and TRUE=1. Therefore you can use FALSE and TRUE in your programs without using a typedef enum....etc. statement. However, Boolean_type is not predefined; therefore, you need the typedef to use the datatype identifier Boolean_type.

The ~ shortcut will not work on Pegasus; e.g. ~jsmith/lab2.txt will not point to the file lab2.txt in jsmith's home directory. You must use the entire pathname: /usr/stu/jsmith/lab2.txt.

man pages: Help for all function calls in Digital C is available in the man pages. Type man <command>, e.g. man fscanf.

There is a utility called 'indent' which will properly indent your C source file. Type 'indent filename.c' . A copy of the unmodified, original file will be moved to filename.c~ and filename.c will now be indented according to GNU C programming standards.

If you prefer to compile under gcc, make sure that your program will work under cc also. This is especially true of the pow() function. It may work under gcc type float or even int but not under Digital C. Therefore, you should use type double to make your code portable. You should also be aware that using math functions such as pow() instead of simple arithmetic operations such as a * a will reduce the performance of your program.

The convention used to denote filenames is either through the use of quotes or angle brackets, e.g. <filename> or 'filename'. You do not include these in your filename!!

The pow() function returns strange results when using int operands and compiling under 'cc'. You can also compile using 'gcc' and pow() works properly when you pass it two integers. gcc is an ANSI C compiler developed by gnu software. Use the same command to compile (e.g. gcc -lm test.c).

math.h To link in the math library in Digital C you must include this switch when compiling your code: cc -lm <sourcefile>. You will need to put an #include <math.h> in the source file also. This is a little quirk of Digital C.

Although the text states that _under_bar_ is a VALID identifier this is not supported in the ANSI C standard: Do not begin identifiers with an underscore; the ANSI C standard reserves these identifiers for internal names.

Hit CTRL-C to abort a program or command. If this doesn't work, login to pegasus a second time and type 'ps'. Look for the PID (process ID) that you want to abort and type 'kill -9 .

'cc -o hw1 hw1.c' will produce an executable named 'hw1'

Pico Issues: The manner in which lines longer than the display width are dealt with is not immediately obvious. Lines that continue beyond the edge of the display are indicated by a '$' character at the end of the line. Long lines are scrolled horizontally as the cursor moves through them. Do NOT put a carriage return into a line in order to see it displayed or you will get a compilation error. If you start pico with pico -w [filename] the stupid program will NOT word wrap and break the lines at the end of the screen (which is what you want). Also, you can hit CTRL-L in pico to refresh the screen.