cdecl

C and C++ type declaration translator

TLDR

Start interactive mode
$ cdecl
Explain a C declaration
$ cdecl explain "int *(*fp)(int)"
Convert English to a C declaration
$ cdecl declare "x as pointer to function returning int"
Explain a complex function declaration
$ cdecl explain "void (*signal(int, void (*)(int)))(int)"
Cast an expression
$ cdecl cast "x into pointer to function returning int"
Declare using English via pipe
$ echo "declare argv as array of pointer to char" | cdecl
Define a typedef
$ cdecl declare "str as typedef pointer to char"

SYNOPSIS

cdecl [-ciV] [command ...]

DESCRIPTION

cdecl (C declaration) translates complex C and C++ type declarations between their cryptic syntax and plain English. It helps programmers understand and construct complicated declarations involving pointers, arrays, and functions.The tool can explain existing declarations like function pointers, arrays of pointers, or pointers to arrays in understandable terms. Conversely, it can generate correct C syntax from English descriptions, helping avoid common declaration mistakes.In interactive mode, cdecl provides a prompt where you can enter multiple explain or declare commands. It handles complex scenarios like pointers to functions returning pointers to arrays, signal handler declarations, and other notoriously confusing C constructs.The C++ mode adds support for references and member pointers. The tool is particularly valuable when working with legacy code, signal handlers, callback functions, or any code with deeply nested type declarations.

PARAMETERS

-+

Use C++ syntax instead of C (same as -c).
-c
Use C++ syntax instead of C.
-i
Enter interactive mode (default if no command given).
-V
Display version information.
explain declaration
Convert C/C++ declaration to English.
declare description
Convert English description to C/C++ declaration.
cast expression
Create a cast expression.
typedef declaration
Create a typedef from a declaration.
set option
Set options (e.g., cplusplus, preansi).
help
Display help in interactive mode.
quit
Exit interactive mode.

INSTALL

sudo apt install cdecl
sudo dnf install cdecl
sudo zypper install cdecl
brew install cdecl
nix profile install nixpkgs#cdecl

CAVEATS

Some very complex or non-standard declarations may not be parsed correctly. The tool focuses on type declarations and does not handle full C/C++ syntax. Newer C++ features (concepts, auto, etc.) may not be supported. Different versions may have slightly different English phrasing.

HISTORY

cdecl was originally written by Graham Ross and later enhanced by several contributors including David Wolverton. It emerged in the 1980s when C's declaration syntax was a frequent source of confusion and bugs. The phrase "declare x as..." became a teaching tool for understanding C's inside-out declaration reading. The tool remains useful today for complex declarations.

SEE ALSO

gcc(1), clang(1), make(1), ctags(1)