cdecl(1) CLIX cdecl(1)
NAME
cdecl, c++decl - Composes C and C++ type declarations
SYNOPSIS
cdecl [language_flag] [-cidDV] [[files ...] | explain ... | declare ... |
cast ... | set ... | help ... | ? ... ]
c++decl [language_flag] [-cidDV] [[files ...] | explain ... | declare ...
| cast ... | set ... | help ... | ? ... ]
explain ...
declare ...
cast ...
FLAGS
Each of the first four flags listed is a language_flag.
-a Specifies the C language based on the (draft proposed) X3j11 ANSI
Standard.
-+ Specifies the C++ language based on B. Stroustrup's The C++
Programming Language book, including the version 2.0 additions to the
language.
-p Specifies the C language based on B. Kernighan and D. Ritchie's The C
Programming Language book.
-r Specifies the C language defined by the Ritchie PDP-11 C Compiler.
-c Creates a program with output that includes semicolons after variable
declarations and curly brace pairs after function declarations.
-i Specifes the input file.
-d Prints debugging information if the source is compiled with the
debugging information turned on.
-D Prints debugging information if the source is compiled with YACC
debugging information turned on.
-V Prints the version numbers of files used to create the process.
DESCRIPTION
The cdecl and c++decl commands encode and decode C and C++ type
declarations. Each command reads the named files for statements in the
2/94 - Intergraph Corporation 1
cdecl(1) CLIX cdecl(1)
language described below. A transformation is made from that language to
C, C++, or pseudo-English. The results of this transformation are written
on standard output. If no files are named, or a dash - is encountered,
the standard input will be read. If the standard input is coming from a
terminal or is specified with the -i flag, a prompt will be written to the
terminal before each line. If the command is invoked as explain, declare
or cast, or the first argument is one of the commands discussed below, the
argument list will be interpreted according to the following grammar
instead of as file names.
The cdecl and c++decl commands may be used as a C program is created with
an editor like vi or emacs. Key in the pseudo-English version of the
declaration and apply cdecl or c++decl as a filter to the line.
Command Language
There are six statements in the language.
declare Composes a C type declaration from a verbose description.
cast Composes a C type cast as might appear in an expression.
explain Decodes a C type declaration or cast and produces a verbose
description.
set Allows command-line flags to be set interactively.
help Provides a help message.
? Provides a help message.
Each statement is separated by a semicolon or a newline.
The following grammar describes the language. In the grammar, words in
the angle brackets (<>) are non-terminals; lower-case words are terminals
that stand for themselves. Upper-case words are other lexical tokens, as
follows:
NOTHING Specifies an empty string.
NAME Specifies a C identifier.
NUMBER Specifies a string of decimal digits.
NL Specifies a newline or semicolon.
Some synonyms are permitted during a declaration, as follows:
character = char
constant = const
enumeration = enum
2 Intergraph Corporation - 2/94
cdecl(1) CLIX cdecl(1)
func = function
integer = int
ptr = pointer
ref = reference
ret = returning
structure = struct
vector = array
The grammar of the language is as follows:
<program> ::= NOTHING
| <program> <stmt> NL
<stmt> ::= NOTHING
| declare NAME as <adecl>
| declare <adecl>
| cast NAME into <adecl>
| cast <adecl>
| explain <optstorage> <ptrmodlist> <type> <cdecl>
| explain <storage> <ptrmodlist> <cdecl>
| explain ( <ptrmodlist> <type> <cast> )
optional-NAME
| set <options>
| help | ?
| quit
| exit
<adecl> ::= array of <adecl>
| array NUMBER of <adecl>
| function returning <adecl>
| function ( <adecl-list> ) returning <adecl>
| <ptrmodlist> pointer to <adecl>
| <ptrmodlist> pointer to member of class
NAME <adecl>
| <ptrmodlist> reference to <adecl>
| <ptrmodlist> <type>
<cdecl> ::= <cdecl1>
| * <ptrmodlist> <cdecl>
| NAME :: * <cdecl>
| & <ptrmodlist> <cdecl>
<cdecl1> ::= <cdecl1> ( )
| <cdecl1> ( <castlist> )
| <cdecl1> [ ]
| <cdecl1> [ NUMBER ]
| ( <cdecl> )
| NAME
<cast> ::= NOTHING
| ( )
| ( <cast> ) ( )
| ( <cast> ) ( <castlist> )
| ( <cast> )
| NAME :: * <cast>
2/94 - Intergraph Corporation 3
cdecl(1) CLIX cdecl(1)
| * <cast>
| & <cast>
| <cast> [ ]
| <cast> [ NUMBER ]
<type> ::= <typename> | <modlist>
| <modlist> <typename>
| struct NAME | union NAME | enum NAME | class NAME
<castlist> ::= <castlist> , <castlist>
| <ptrmodlist> <type> <cast>
| <name>
<adecllist> ::= <adecllist> , <adecllist>
| NOTHING
| <name>
| <adecl>
| <name> as <adecl>
<typename> ::= int | char | double | float | void
<modlist> ::= <modifier> | <modlist> <modifier>
<modifier> ::= short | long | unsigned | signed | <ptrmod>
<ptrmodlist> ::= <ptrmod> <ptrmodlist> | NOTHING
<ptrmod> ::= const | volatile | noalias
<storage> ::= auto | extern | register | auto
<optstorage> ::= NOTHING | <storage>
<options> ::= NOTHING | <options>
| create | nocreate
| interactive | nointeractive
| ritchie | preansi | ansi | cplusplus
| debug | nodebug | yydebug | noyydebug
EXAMPLES
Command-line examples should be entered on a single line.
1. This example declares an array of pointers to functions like malloc().
declare fptab as array of pointer to function returning pointer
to char
The result of this command is the following:
char *(*fptab[])()
2. To decode the result of the example above, use the following language:
explain char *(*fptab[])()
3. To describe the proper declaration for the signal() function and
4 Intergraph Corporation - 2/94
cdecl(1) CLIX cdecl(1)
ignore function prototypes, use the following syntax:
declare signal as function returning pointer to function
returning void
This command produces the following output:
void (*signal())()
The function declaration that results has two sets of empty
parentheses. To determine where to put the parameters, use the
following syntax:
declare signal as function (arg1,arg2) returning pointer to function
returning void
This syntax provides the following solution (when run with the -c
flag):
void (*signal(arg1,arg2))(){ }
To add in the function prototypes for a function such as exit(), use
the following declaration:
declare exit as function (retvalue as int) returning void
The following results are produced:
void exit(int retvalue) { }
4. This example is a more complex and uses function prototypes. For
example, the signal() function could be fully defined as follows:
declare signal as function(x as int, y as pointer to
function(int) returning void) returning pointer to
function(int) returning void
The following output is given (when the -c flag is used):
void (*signal(int x, void (*y)(int )))(int ){ }
5. The cdecl and c++decl commands can help determine where to put the
const and volatile modifiers in declarations.
declare foo as pointer to const int
2/94 - Intergraph Corporation 5
cdecl(1) CLIX cdecl(1)
This is the resulting output.
const int *foo
In another case, the following syntax is used:
declare foo as const pointer to int
This syntax generates the following output:
int * const foo
6. The c++decl command can help with declaring references, as shown in
this example.
declare x as reference to pointer to character
The following output is produced.
char *&x
7. The c++decl command can help with pointers to member of classes, thus
declaring a pointer to an integer member of a class X with the
following:
declare foo as pointer to member of class X int
The following output is given:
int X::*foo
In a related example, the following syntax is entered:
declare foo as pointer to member of class X function
(arg1, arg2) returning pointer to class Y
The following output is generated:
class Y *(X::*foo)(arg1, arg2)
NOTES
The pseudo-English syntax is excessively verbose.
There is a wealth of semantic checking that is not done.
The cdecl command's scope is intentionally small. It does not decode
6 Intergraph Corporation - 2/94
cdecl(1) CLIX cdecl(1)
initializations. It expects storage classes to be at the beginning of a
declaration, followed by the the const, volatile and noalias modifiers,
followed by the type of the variable. The cdecl command does not decode
variable length argument lists. (This includes the ,... syntax.)
The cdecl command interprets all declarations as external definitions.
Some declaration contexts in C allow more flexibility than this. The
following is an example:
declare argv as array of array of char
The cdecl command will respond with the following messages:
Warning: Unsupported in C -- 'Inner array of unspecified size'
(maybe you mean "array of pointer")
char argv[][]
Tentative support for the noalias keyword has been put in because it is in
the current ANSI specifications.
DIAGNOSTICS
The declare, cast and explain statements try to point out constructions
that are not supported in C. In some cases, a guess is made as to what
was really intended. In these cases, the C result is a toy declaration
whose semantics will work only in Algol-68. The list of unsupported C
constructs is dependent on which version of the C language is being used.
The set of supported C++ constructs is a superset of the ANSI set, with
the exception of the noalias keyword.
RELATED INFORMATION
The ANSI National Standard X3J11 (draft proposed)
Section 8.4 of the C Reference Manual within The C Programming Language by
B. Kernighan & D. Ritchie
Section 8 of the C++ Reference Manual within The C++ Programming Language
by B. Stroustrup
2/94 - Intergraph Corporation 7