LinuxCommandLibrary

cdecl

C and C++ type declaration translator

TLDR

Start interactive mode

$ cdecl
copy
Explain a C declaration
$ cdecl explain "[int *(*fp)(int)]"
copy
Convert English to C declaration
$ cdecl declare "[x as pointer to function returning int]"
copy
Cast an expression
$ cdecl cast "[x into pointer to function returning int]"
copy
Explain a function declaration
$ cdecl explain "[void (*signal(int, void (*)(int)))(int)]"
copy
Declare using English in one command
$ echo "declare x as array 10 of pointer to char" | cdecl
copy
Set output to C++ mode
$ cdecl set options cplusplus
copy

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

-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.
set option
Set options (e.g., cplusplus, preansi).
help
Display help in interactive mode.
quit
Exit interactive mode.

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), cscope(1), ctags(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community