Skip to content

Latest commit

 

History

History
94 lines (63 loc) · 2.17 KB

cdecl.pod

File metadata and controls

94 lines (63 loc) · 2.17 KB

NAME

cdecl -- Translate C declarations to English

SYNOPSIS

cdecl

DESCRIPTION

cdecl reads a C declaration from its input and translates it to English terms which are sent as output.

This program was written following the recommendations and algorithm presented by Peter van der Linden on his book "Expert C Programming - Deep C Secrets". Writing this program was a programming challenge given in Chapter 3.

There have been many cdecl versions written along history. This one in particular -- although very simple -- has an easy to understand parsing algorithm and is relatively complete. Recognized types include:

void
char
short
int
long
signed
unsigned
float
double
struct
union
enum

And the following language features:

- Arrays

Interpreted with or without any size.

- Functions

Interpreted with arguments ignored.

- Qualifiers

Both volatite and const (which is translated as readonly)

- Pointers

EXAMPLES

Calling the program and writing the declaration followed by a new line will produce, for example:

$ cdecl
int * const n
n is readonly pointer to int

$ cdecl
char *f()
f is function returning pointer to char

$ cdecl
long *(*(*x)[10])()
x is pointer to array with size 10 of pointer to function returning pointer to long

CAVEATS

Due to the way it is constructed, this version of cdecl won't produce any warning or error if bad syntax is encountered. There are no checks for invalid constructs either, such as an array of functions.

The goal (as described in the book) was not to build a complete parser but rather implement and practice an easy algorithm.

AUTHORS & HISTORY

This software and manual were written by Cesar Tessarin originally on July 5th 2011, rewritten partially and updated on Oct. 2017. However, all credit of the internal algorithm and design goes to Peter van der Linden since (as stated above) this was an exercise from his book:

Expert C Programming - Deep C Secrets, 1st edition

Peter van der Linden (C) 1994 Sun Microsystems, Inc. ISBN:978-0-131-77429-2