Linux repositories inspector

cdecl(1)

PJL TOOLS
January 24, 2020
Aliases: c++decl(1)

cdecl

Turn English phrases to C or C++ declarations

cutils

C source code utilities

NAME

cdecl, c++decl - compose and decipher C & C++ declarations and casts

SYNOPSIS

cdecl [options] [file ...]
c++decl [options] [file ...]
cast [options] english
declare [options] english
explain [options] gibberish

DESCRIPTION

‘‘I’m still uncertain about the language declaration syntax, where in declarations, syntax is used that mimics the use of the variables being declared. It is one of the things that draws strong criticism, but it has a certain logic to it.’’
— Dennis M. Ritchie
‘‘I consider the C declarator syntax an experiment that failed.’’
— Bjarne Stroustrup
cdecl is a program for composing and deciphering C (or C++) declarations or casts, aka ‘‘gibberish.’’ It can be used interactively on a terminal or accept input from either the command line or standard input.

INVOCATION

Executable Name

cdecl may be invoked under a number of different names (by either renaming the executable or creating either a symbolic or hard link to it). If it is invoked as:
cdecl Runs with the latest supported version of C as the default language.
c++decl | cppdecl | cxxdecl
Runs with the latest supported version of C++ as the default language.
cast | declare
Runs with the latest supported version of C as the current language interpreting the rest of the command-line (if given) as pseudo-English, performs the conversion to gibberish, and exits.
explain Runs with the latest supported version of C as the current language interpreting the rest of the command-line (if given) as gibberish, performs the conversion to pseudo-English, and exits.
For example (where $ is the shell prompt):

$ declare p as pointer to const pointer to const int const int *const *p;

When using explain, care must be taken either to escape or quote shell metacharacters:

$ explain ’int *const (*p)[4]’ declare p as pointer to array 4 of const pointer to int

First Argument

cdecl will also behave as above if the first non-option argument on the command-line or the first whitespace separated word thereof is one of cast, const, declare, define, dynamic, explain, help, namespace, reinterpret, set, static, typedef, or using:

$ cdecl declare p as pointer to array 4 of int int (*p)[4];
$ c++decl ’reinterpret cast n into pointer to unsigned’ reinterpret_cast<unsigned*>(n)

Standard Input

If no file names are given, or a file name of ‘‘-’’ is encountered, standard input will be read until end-of-file is encountered or either the exit, q, or quit command is read.
You can use cdecl as you create a C (or C++) program from within an editor. For example, in vi(1), type the declaration in pseudo-English, then filter the line through cdecl:

!!cdecl<CR>

where <CR> is the return key.

Interactive Input

If standard input is coming from a terminal (or either the --interactive or -i option is specified), a prompt of either cdecl> or c++decl> will be written to the terminal before each line of input. The prompt can be turned off by either the --no-prompt or -p option, or the set noprompt command.
cdecl uses the GNU readline(3) library (if available and compiled in) to provide keyword completion, command-line history, and editing.

File Input

cdecl reads the named files for statements in the language described below. A transformation is made from that language to C (or C++) for either cast or declare, or pseudo-English for explain. The results of this transformation are written to standard output (unless either the --output or -o option is given).

OPTIONS

An option argument f means file and s means string.
--alt-tokens | -a
Turns on alternative token output. The alternative tokens are: and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, and xor_eq.
--color=s | -k s
Sets when to colorize output to s (which is case-insensitive). (See the CDECL_COLORS environment variable about colorization.) The choices for s are:
always Always colorize.
auto Synonym for isatty.
isatty Colorize only when standard output is connected to a TTY (terminal) and the TERM environment variable is not empty and not equal to dumb.
never Never colorize.
not_file Colorize only when not writing to a regular file (hence writing to a TTY or pipe) and the TERM environment variable is not empty and not equal to dumb. (Specifically, fstat(3) is called on standard output: colorize only if S_IFREG is false.)
This is more useful than isatty since it accomodates the common case of allowing color output to be piped to less(1) and still display in color since less understands SGR (‘‘Select Graphic Rendition’’) ASCII terminal escape sequences that produce color.
not_isreg Synonym for not_file.
tty Synonym for isatty.
The default is not_file.
--config=f | -c f
Specifies the configuration file f to read (see CONFIGURATION FILE).
--debug | -d
Turns on debugging output (if compiled in). The additional JSON-like output is of an abstract syntax tree as it is being constructed from user input while the parser is reducing grammar productions. (This is a debugging aid for developers of cdecl itself.)
--digraphs | -2
Turns on digraph output for [ and ].
--explain | -e
Assumes explain when an input line doesn’t start with any command.
--explicit-int=s | -I s
Sets the integer types to s (which is case-insensitive) that should have int explicitly included in declarations. (Normally, int is omitted for short, long, long long, or unsigned declarations where int is implied.) Valid formats for s are:
i All signed integer types.
u All unsigned integer types.
[u]{i|s|l[l]}
Possibly unsigned int, short, long, or long long.
Multiple formats may be given, one immediately after the other, e.g., usl means unsigned short and long. Parsing is greedy so commas may be used to separate formats. For example, ulll is parsed as unsigned long long and long whereas ul,ll is parsed as unsigned long and long long. Note that since u is both a shorthand and a modifier, iu means all signed and unsigned integer types whereas ui means just unsigned int.
--file=f | -f f
Reads commands from file f.
--help | -h
Prints a help message to standard error and exits.
--interactive | -i
Forces interactive mode, that is turns on prompting (unless either the --no-prompt or -p option is given) and enables line-editing and history. (This is the default when connected to a terminal.)
--language=s | -x s
Specifies which version of what language s (which is case-insensitive) to use. (See C AND C++ LANGUAGE VERSIONS for valid languages.) The default is C18 (for cdecl) and C++20 (for c++decl).
--no-config | -C
Suppresses reading of any configuration file, even one explicitly specified via either --config or -c.
--no-prompt | -p
Suppresses printing of the prompt in interactive mode.
--no-semicolon | -s
Suppresses printing of a trailing semicolon for C (and C++) declarations.
--no-typedefs | -t
Suppresses predefining standard types, e.g., size_t, uint8_t, etc.
--output=f | -o f
Sends all non-error output to file f.
--trigraphs | -3
Turns on trigraph output for [, ], ^, |, and ~.
--version | -v
Prints the version number to standard error and exits.
--yydebug | -y
Turns on bison(1) debugging output (if compiled in). The additional output is of grammar productions as they are being reduced by the parser. (This is a debugging aid for developers of cdecl itself.)

C AND C++ LANGUAGE VERSIONS

The argument to the --language or -x option or the set command is one of the following versions (which are case-insensitive):
C Use the latest supported version of the C language.
CK&R | K&R | K&RC | CKNR | KNR | KNRC
Use the pre-ANSI Kernighan & Ritchie version of the C language as given in the first edition of The C Programming Language.
C89 Use the C89 (first ANSI C) version of the C language. Adds support for const, enum, long double, long long, signed, void, volatile, and function prototypes.
C95 Use the C95 version of the C language. Adds support for wchar_t.
C99 Use the C99 version of the C language. Adds support for _Bool, _Complex, _Imaginary, restrict, inline functions, and static, type-qualified, and variable length array function arguments.
C11 Use the C11 version of the C language. Adds support for _Alignas, _Atomic, char16_t, char32_t, _Noreturn, and _Thread_local,
C18 Use the C18 version of the C language. (Minor revision: no new features. Equivalent to C11.)
C++ Use the latest supported version of the C++ language.
C++98 Use the C++98 version of the C++ language. Adds support for class, constructors, destructors, exception specifications (throw), mutable data members, namespace, new-style casts, overloaded operators, references, pointers to class members, user-defined conversion, and virtual functions.
C++03 Use the C++03 version of the C++ language. (Minor revision; no new features. Equivalent to C++98.)
C++11 Use the C++11 version of the C++ language. Adds support for alignas, auto, [[carries_dependency]], char16_t, char32_t, enum class, noexcept, [[noreturn]], rvalue references, thread_local, using, the function trailing return-type syntax, user-defined literals, and member function ref-qualfiers, final, and override.
C++14 Use the C++14 version of the C++ language. Adds support for auto functions and [[deprecated]].
C++17 Use the C++17 version of the C++ language. Adds support for inline variables, [[maybe_unused]], and [[nodiscard]].
C++20 Use the C++20 version of the C++ language. Adds support for char8_t, consteval, and operator<=>.

CDECL LANGUAGE

Commands

cdecl has the following commands:
cast s-name {as|into|to} english
Composes a C (or C++) cast from pseudo-English.
{const|dynamic|reinterpret|static} cast s-name {as|into|to} english
Composes a C++ new-style cast from pseudo-English.
declare s-name as english [aligned [as] {number [bytes] | english}]
Composes a C (or C++) declaration from pseudo-English.
declare operator as english
For C++ only, composes an overloaded operator declaration from pseudo-English.
define s-name as english
Defines a type (typedef) from pseudo-English.
explain gibberish
Deciphers a C (or C++) declaration or new-style cast (C++ only) into pseudo-English.
explain (gibberish)[s-name]
Deciphers a C (or C++) cast into pseudo-English.
scope-c s-name { [ scope-c | { typedef | using } ; ]}
For C++ only, executes one of the namespace, typedef, or using commands within the scope of s-name thus declaring a type within that scope.
set [option [= value] | options | lang]
In the first form, sets a particular option (see Set Options for valid options); in the second form, prints the current value of all options; in the third form, sets the current language to lang. If no argument is given, it’s equivalent to the second form.
show { s-name | all | predefined | user } [typedef]
Shows the definition for a previously defined type (via define, typedef, or using) having s-name; or shows all, predefined-only, or user-defined-only types. By default, the definitions are shown in pseudo-English. If typedef is given, the definitions are shown as typedef declarations.
typedef gibberish
Defines a type via a C (or C++) typedef declaration.
using name = gibberish
For C++11 or later only, defines a type via a using declaration.
{ help | ? } [ command[s] | english ]
Prints help that’s sensitive to the current programming language (C or C++). By default or when command or commands is given, prints help on cdecl’s commands (this section); if english is given, gives help on pseudo-English (see English below).
exit | quit | q
Quits cdecl.
where:
name A valid C (or C++) identifier.
operator A valid C++ operator.
s-name For C, is the same as name; for C++, is either the same as name or is a scoped name that may always be specified using ::, e.g., S::T::x, or in an english context, may alternatively be specified as s-name [of scope-e s-name]*.
scope-c One of: class, namespace, struct, or union.
scope-e One of: class, namespace, scope, struct, or union.
Commands are terminated by either a semicolon or newline. However, commands may be given that span multiple lines when newlines are escaped via \. When a newline is escaped, the next prompt (if interactive and enabled) changes to either cdecl+ or c++decl+ to indicate that the current line will be a continuation of the previons line.

English

In what follows, [] means zero or one, * means zero or more, {} means one of, and | means alternate. The only punctuation characters used in pseudo-English are hyphens in hyphenated words and parentheses around and commas between constructor, function, operator, or block arguments.
English is one of:
store* array [[static] cv-qual* {number|*}] of english
store* variable [length] array cv-qual* of english
block [([args])] [returning english]
store+ constructor [([args])]
[virtual] destructor
store* fn-qual* [[non-]member] function [([args])] [returning english]
store* fn-qual* [[non-]member] operator [([args])] [returning english]
cv-qual* pointer to [member of class s-name] english
[rvalue] reference to english
store* user-defined conversion [operator] [of scope-e s-name]* returning english
store* user-defined literal [([args])] [returning english]
store* modifier* [C-type]
{ enum [class | struct] | class | struct | union } s-name
where:
args A comma-separated list of s-name, english, s-name as english; or one of varargs, variadic, or ... (ellipsis).
C-type One of: auto (C++11 or later), bool, char, char8_t, char16_t, char32_t, wchar_t, int, float, double, or void.
cv-qual One of: _Atomic, const, restrict, or volatile.
fn-qual One of: const, reference, rvalue reference, or volatile.
modifier One of: short, long, signed, unsigned, _Complex, or _Imaginary.
number One of a decimal, octal (if starting with 0), hexadecimal (if starting with either 0x or 0X), or binary (if starting with either 0b or 0B) number.
store One of: auto (C, or C++03 or earlier), block, carries-dependency, consteval, constexpr, deprecated, extern, final, friend, inline, maybe-unused, mutable, nodiscard, non-throwing, noreturn, override, register, static, thread-local, typedef, virtual, or pure virtual.
If returning english is omitted, it’s equivalent to returning void.

Synonyms

Some synonyms are permitted within pseudo-English. The words on the left are synonyms for what’s on the right:

atomic _Atomic automatic auto _Bool bool carries-dependency carries_dependency character char command commands complex _Complex constant const enumeration enum external extern func function imaginary _Imaginary integer int len length maybe-unused maybe_unused mbr member no-exception noexcept non-discardable nodiscard non-mbr non-member non-returning _Noreturn non-throwing throw() noreturn _Noreturn oper operator overridden override predef predefined ptr pointer ref reference restricted restrict ret returning structure struct type typedef _Thread_local thread_local user-def user-defined var variable varargs ... variadic ... vector array

Gibberish

Gibberish is any supported C (for cdecl) or C++ (for c++decl) variable, function, constructor, destructor, overloaded operator, user-defined conversion, or user-defined literal declaration, or type cast. (See EXAMPLES for examples and CAVEATS for unsupported declarations.)
Gibberish also includes support for Apple’s ‘‘blocks’’ syntax and the __block storage class.

Predefined Types

The following types are predefined (unless either the --no-typedefs or -t option is given):
max_align_t, ptrdiff_t, rsize_t, sig_atomic_t, size_t, ssize_t,
div_t, imaxdiv_t, ldiv_t, lldiv_t,
intmax_t, uintmax_t, intptr_t, uintptr_t,
int8_t, int16_t, int32_t, int64_t,
int_fast8_t, int_fast16_t, int_fast32_t, int_fast64_t,
int_least8_t, int_least16_t, int_least32_t, int_least64_t,
uint8_t, uint16_t, uint32_t, uint64_t,
uint_fast8_t, uint_fast16_t, uint_fast32_t, uint_fast64_t,
uint_least8_t, uint_least16_t, uint_least32_t, uint_least64_t
atomic_ptrdiff_t, atomic_size_t,
atomic_bool, atomic_char, atomic_schar,
atomic_char16_t, atomic_char32_t, atomic_wchar_t,
atomic_short, atomic_int, atomic_long, atomic_llong,
atomic_uchar, atomic_ushort, atomic_uint,
atomic_ulong, atomic_ullong,
atomic_intmax_t, atomic_uintmax_t,
atomic_intptr_t, atomic_uintptr_t,
atomic_int_fast8_t, atomic_int_fast16_t,
atomic_int_fast32_t, atomic_int_fast64_t,
atomic_uint_fast8_t, atomic_uint_fast16_t,
atomic_uint_fast32_t, atomic_uint_fast64_t,
atomic_int_least8_t, atomic_int_least16_t,
atomic_int_least32_t, atomic_int_least64_t,
atomic_uint_least8_t, atomic_uint_least16_t,
atomic_uint_least32_t, atomic_uint_least64_t,
blkcnt_t, blksize_t, dev_t, fd_set, fpos_t, ino_t, mbstate_t, mode_t, nfds_t, nlink_t, off_t,
clock_t, clockid_t, time_t, suseconds_t, useconds_t,
errno_t, FILE, gid_t, pid_t, rlim_t, sigset_t, uid_t, wint_t,
in_addr_t, in_port_t, sa_family_t, socklen_t,
std::byte, std::exception, std::max_align_t, std::nullptr_t, std::ptrdiff_t, std::sig_atomic_t, std::size_t, std::div_t, std::imaxdiv_t, std::ldiv_t, std::lldiv_t, std::u16string, std::u32string,
std::streambuf, std::wstreambuf, std::streamoff, std::streamsize, std::string, std::wstring,
std::partial_ordering, std::strong_equality, std::strong_ordering, std::weak_equality, std::weak_ordering

Set Options

The set command takes several options (which ignore hyphens). Unambiguous option abbreviations may be used.
[no]alt-tokens
Turns [off] on alternative token output.
[no]debug
Turns [off] on debugging output (if compiled in) — default is off.
nographs
Turns off either digraph or trigraph output, i.e., reverts to emitting all characters as-is.
digraphs
Turns on digraph output for [ and ].
[no]explain-by-default
Turns [off] on explain being assumed when an input line doesn’t start with any command — default is off.
explicit-int=s
Turns on explicit int for the integer types s — default is none. (See the --explicit-int or -I option for details.)
noexplicit-int
Turns off explicit int for all integer types.
lang=s
Use s (which is case-insensitive) as the current language. (See C AND C++ LANGUAGE VERSIONS for valid languages.)
lang Shorthand for lang=lang.
options
Prints the current value of all options.
[no]prompt
Turns [off] on the prompt — default is on.
[no]semicolon
Turns [off] on printing a semicolon at the end of a C (or C++) declaration — default is on.
trigraphs
Turns on trigraph output for [, ], ^, |, and ~.
[no]yydebug
Turns [off] on bison(1) debugging output (if compiled in) — default is off.

CONFIGURATION FILE

The cdeclrc file (by default, ~/.cdeclrc) is used to configure cdecl by executing the contained commands on start-up (unless either the --no-config or -C option is given). The commands useful within a configuration file are:
o class, define, namespace, struct, typedef, union, or using to pre-define user-specific types so that they may be subsequently used when either composing or deciphering declarations.
o set to set the language or enable digraph or trigraph support initially.
Configuration files may include blank lines, C-style /* */ comments, C++-style // comments, and C preprocessor directives #, all of which are ignored.

EXAMPLES

To declare an array of pointers to functions that are like malloc(3):

cdecl> declare fptab as array of pointer to function \ cdecl+ returning pointer to void void *(*fptab[])();

When you see this declaration in someone else’s code, you can make sense out of it by doing:

cdecl> explain void *(*fptab[])()

The proper declaration for signal(2), ignoring function prototypes, is easily described in cdecl’s language:

cdecl> declare signal as function \ cdecl+ returning pointer to function returning void void (*signal())();

That function declaration has two sets of empty parentheses. The author of such a function might wonder where to put the parameters:

cdecl> declare signal as function (sig, func) \ cdecl+ returning pointer to function returning void void (*signal(sig,func))();

If we want to add in the function prototypes, the function prototype for a function such as _exit(2) would be declared with:

cdecl> declare _exit as function (retval as int) returning void void _exit(int retval);

As a more complex example using function prototypes, signal(2) would be fully defined as:

cdecl> declare signal as function \ cdecl+ (sig as int, \ cdecl+ f as pointer to function (int) returning void) \ cdecl+ returning pointer to function (int) returning void void (*signal(int sig, void (*f)(int)))(int);

This is made more comprehensible with one of define, typedef, or using:

cdecl> define pfi_rv as pointer to function (int) returning void cdecl> declare signal as function \ cdecl+ (sig as int, f as pfi_rv) returning pfi_rv pfi_rv signal(int sig, pfi_rv f);

cdecl can help figure out where to put const and volatile modifiers:

cdecl> declare pc as pointer to const int const int *pc;
cdecl> declare cp as const pointer to int int *const cp;

c++decl can help with declaring references:

c++decl> declare rp as reference to pointer to char char *&rp;

c++decl can help with pointers to member of classes:

c++decl> declare p as pointer to member of class C int int C::*p;

and:

c++decl> declare p as pointer to member of class C \ c++decl+ function (i as int, j as int) \ c++decl+ returning pointer to class D class D *(C::*p)(int i, int j)

To define types within scopes:

c++decl> define A::B::T1 as int c++decl> define T2 of scope A as int c++decl> define T3 of scope B of scope A as int c++decl> define T4 of scope A::B as int c++decl> define T5 of class C::D as int c++decl> class C { typedef int T; }; c++decl> class C1 { class C2 { typedef int T; }; }; c++decl> struct S { typedef int T; }; c++decl> namespace N { typedef int T; }; c++decl> namespace N::M { typedef int T; }; c++decl> union U { typedef int T; };

EXIT STATUS

0 Success.
64 Command-line usage error.
65 Syntax or semantic error.
66 Open file error.
70 Internal software error. (Please report the bug.)
71 System error.
73 Create file error.
74 I/O error.

ENVIRONMENT

CDECL_COLORS
This variable specifies the colors and other attributes used to highlight various parts of the output in a manner similar to the GCC_COLORS variable used by gcc.
As with gcc, the value is composed of a colon-separated sequence of capabilities. Each capability is of the form name[=SGR] where name is a capability name and SGR, if present, is a ‘‘Select Graphic Rendition’’ value that is a semicolon-separated list of integers in the range 0-255. An example SGR value is 31;1 that specifies a bright red foreground on the terminal’s default background.
Capability names in upper-case are unique to cdecl; those in lower-case are upwards compatibile with gcc.
caret=SGR SGR for the caret pointing to the error on the line above (as with gcc). The default is 36;1 (bright green foreground over current terminal background).
error=SGR SGR for the word ‘‘error.’’ The default is 31;1 (bright red foreground over current terminal background).
HELP-keyword=SGR SGR for keywords in help output. The default is 1 (bold terminal foreground current terminal background).
HELP-nonterm=SGR SGR for nonterminals in help output. The default is 36 (cyan foreground over current terminal background).
HELP-punct=SGR SGR for punctuation in help output. The default is 30;1 (dark dray forgreound over current terminal background).
HELP-title=SGR SGR for titles in help output. The default is 34;1 (bright blue foreground over current terminal background).
locus=SGR SGR for location information in error and warning messages. The defualt is 1 (bold current foreground over current terminal background).
PROMPT=SGR SGR for the prompt. The default is 32 (green foreground over current terminal background).
warning=SGR SGR for the word ‘‘warning.’’ The default is 33;1 (bright yellow foreground over current terminal background).
Other gcc capabilities, if present, are ignored because they don’t apply in cdecl. The term ‘‘color’’ is used loosely. In addition to colors, other character attributes such as bold, underlined, reverse video, etc., may be possible depending on the capabilities of the terminal.
COLUMNS
The number of columns of the terminal on which cdecl is being run. Used to get the terminal’s width for limiting error and warning messages’ length. Takes precedence over the number of columns specified by the TERM variable.
GCC_COLORS
This variable is used for compatibility with gcc. It is used exactly as CDECL_COLORS but only when CDECL_COLORS is either unset or empty. Capabilities in gcc that are unsupported by cdecl (because they don’t apply) are ignored.
HOME The user’s home directory: used to locate the default configuration file. If unset, the home directory is obtained from the password database entry for the effective user. If that fails, no default configuration file is read.
TERM The type of the terminal on which cdecl is being run.

FILES

~/.cdeclrc
The default configuration file containing user-specified define, typedef, or using commands (see CONFIGURATION FILE).
~/.inputrc
Individual readline(3) initialization file.

BUGS

On macOS (up through to at least version 10.14, aka Mojave), the readline(3) API is provided, but backed by libedit that has a bug that prevents color prompts from working correctly. As such, the PROMPT color cabapility is ignored on systems that do not provide genuine GNU readline(3).

CAVEATS

Unsupported Declarations

The following types of declarations are not currently supported:
0step]. Multiple comma-separated declarations are not supported:

int i, *p; // not supported
0[step]. Only enum, class, struct, and union names and scoped type declarations are supported; complete declarations are not:

struct S s; // supported struct S { typedef int Int; }; // supported struct S { int i; char c; } s; // not supported
0[step]. While file-scope constructor declarations are supported, in-class constructor declarations without at least one storage-class-like type are not:

C::C() // supported C::C(int) // supported explicit C(int) // supported C() // not supported
This is because in-class constructor declarations without a storage-class-like type and ordinary function declarations are ambiguous in an LALR(1) parser:

C(T) // constructor C with T argument C(x) // variable x of type C with unneeded ()
0[step]. C++ decltype, function default arguments, and template declarations are not supported.
0[step]. For function exception specifications, only noexcept, noexcept(true), noexcept(false), and throw(), are supported; arbitrary expressions for noexcept or types for throw are not supported.
0[step]. Namespace alias declarations are not supported:

namespace ALN = A_Long_Name; // not supported
0[step]. Multiple _Alignas or alignas specifiers in the same declaration are not supported.
0[step]. Only integer literals or types as the argument to either the _Alignas or alignas specifier are supported; arbitrary expressions are not.
0[step]. Only simple C++ attribute specifiers like [[this]] are supported; attribute specifiers with namespaces or arguments are not.
0[step]. C++20 contracts ([[assert]], [[ensures]], and [[expects]]) are not supported.

Other Minor Caveats

0step]. When converting from pseudo-English to a C++ declaration, enum, class, struct, and union types include the corresponding keyword explicitly in the result even though it isn’t needed in C++:

c++decl> declare p as const pointer to struct S struct S *const p;
This is because, when going the other way from a C++ declaration to pseudo-English, the declaration parser can’t know that an arbitrary name, in this example, S, is one of an enum, class, struct, or union name. While the keyword could be elided from the output of declare, it isn’t in order to have the output be ‘‘round-trippable’’ when used as input to explain.
However, define, typedef, or using can be used to define the type:

c++decl> define S as struct S c++decl> declare p as const pointer to S S *const p;
0[step]. When converting from one of the C++ overloaded operators &, *, +, ++, -, or --, to pseudo-English when declared as:

T operator OP(U);
i.e., taking one argument, it’s ambiguous (to cdecl) between being a member or non-member operator since cdecl doesn’t have the context in which the operator is declared. If it were declared in-class, e.g.:

class T { public:
// ...
T operator OP(U); };
then clearly it’s a member operator; if it were declared at file scope, then clearly it’s a non-member operator; but cdecl doesn’t have this context. In such cases, cdecl omits either member or non-member from its output.
0[step]. When converting from pseudo-English to a C++ declaration for either auto or a reference or an rvalue reference variable that is not a function argument, the output doesn’t include an initializer:

c++decl> declare x as auto auto x; c++decl> declare r as reference to int int &r;
These are illegal C++ declarations since auto and such references must be initialized.
0[step]. While explain supports the C++11 function trailing return-type syntax, declare always prints in the traditional syntax.
0[step]. Only a name may be cast; casting an expression is not supported.
0[step]. When converting from or to a C++ new-style cast, no semantic validation is performed to determine whether the type of cast is legal.
0[step]. When a predefined type, e.g., size_t, uint16_t, etc., is shown (via the show command), the underlying type is merely typical and does not necessarily match the underlying type on any particular platform.
0[step]. An integer literal given as the argument for an alignment specifier is only checked to ensure it’s either zero or a power of two; it is not checked to see whether it meets the minimum alignment for the type.

AUTHORS

cdecl has been around since the mid-1980s and there have been many versions of cdecl, some with different subsets of authors. This list is a best-effort at a union of all authors. In reverse chronological order:
Paul J. Lucas <>
Peter Ammon <>
David R. Conrad <>
Alexander Dupuy <>
Merlyn LeRoy <>
Tony Hansen <>
David Wolverton <>
Graham Ross
⇧ Top