test2.h


Headers Index Help      Within this page: Functions Constants Variables


Overview

TEST2.C - The second cdoc test program. This program compiles, but many of its declarations are meaningless test cases.

Functions

Include files defined in the header, test2.h, are shown in italics.


calculate

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

int calculate();

Check the operation of the MAX macro.

In: test2.c

Return to the top

main

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

int main(int argc, char **argv);

The program is controlled from here. Nothing else much to say, really.

In: test2.c

Return to the top

old_style

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

old_style(a,b)
int a;
int b;

A <K&R> definition.

In: test2.c

Return to the top

sentence

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

void sentence(text)
char *text;

sentence() - A subsidiary function to generate output. ==========

In: test2.c

Return to the top

spectrum

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

colour_t spectrum(my_typedef_struct a,
                  colour_t def);

Example that accepts a typedef and returns another.

In: test2.c

Return to the top

struct_builder

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

struct my_struct *struct_builder(colour_t tint);

Another example. This one accepts a typedef and returns a struct.

In: test2.c

Return to the top

union_diddle

#include <stdio.h>
#include "testdummy.h"
#include "test2.h"

void union_diddle(union u2 x);

Test the accessibility of union fields

In: test2.c

Return to the top

Constants

ADDRESSOF
#define ADDRESSOF &x
DECISION
#define DECISION  { "Yes", "No" }
FALSE
#define FALSE     0
HEX
enum { HEX = 1,
       HAX = 2
     };
L2C
#define L2C ( x ) ( x & 0xFF )
This symbol appears in #undef statements in test2.h
LBRACKET
#define LBRACKET  "{"
MAGIC
enum { MAGIC = -7 };
MAX
#define MAX(a,b)  ( a > b ? a )
MIN
#define MIN(a,b)  ( a < b ? a )
NOVEL
#define NOVEL     "This is my story"
ONE
enum{ONE=1,TWO=2};
RBRACKET
#define RBRACKET  '}'
RED
enum
{
   RED = 0,
   ORANGE = 1,
   YELLOW = 2,
   GREEN,
   BLUE,
   INDIGO,
   VIOLET
};
TRUE
#define TRUE      1
TWOLINES
#define TWOLINES(a,b)  printf("%s\n", a);\
                       printf("%s\n", b)
decide
const char *decide[] = DECISION;
mth
const char *mth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
                     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
mth_no
enum mth_no         {JAN,   FEB,   MAR,   APR,   MAY,   JUN,
                     JUL,   AUG,   SEP,   OCT,   NOV,   DEC};
new_value
const int new_value = 1;
onoff
const char *onoff[] = { "On", "Off" };
privacy_values
enum privacy_values { OFF = 0, ON };
string
const char string[] = "My string";
switch_state
const int  switch_state[] = { 1, 0 };
zero
const int zero = 0;

Return to the top

Variable type definitions

colour_t
typedef int colour_t;
complex
struct complex {double re; double im;};
coord
struct coord{double x; double y;};
junk
struct junk{int i; int j;} kipple;
my_struct
struct my_struct {
   int f3;
   char f4;
};
my_typedef_struct
typedef struct {
   int f1;
   char f2;
} my_typedef_struct;
name
struct {int wrongly; int placed;}name;
u1
union u1
{
        int i;
        char c;
};
u2
union u2{char c[4]; float r;};
u3
union u3
{
   my_typedef_struct mts;
   struct junk       cmpl;
};

Return to the top

Global Variable definitions

errno
extern int errno;
global_string
char *global_string = "A sentence in a string";
header_int
int header_int;
life_cycle
char *life_cycle[] = { "egg",  "tadpole",
                       "frog", "stork bait" };
stasis
static int stasis = 3;
value_3
char *value_3 = "3 = 3";

Return to the top