LinuxCommandLibrary

cdecl

Translate C declarations to English (and vice versa)

TLDR

Compose English phrase into C declaration, and create [c]ompilable output (include ; and {})

$ cdecl -c [phrase]
copy

Explain C declaration in English
$ cdecl explain [C_declaration]
copy

Cast a variable to another type
$ cdecl cast [variable_name] to [type]
copy

Run in [i]nteractive mode
$ cdecl -i
copy

SYNOPSIS

cdecl

DESCRIPTION

The cdecl command is a utility that translates C declarations into English and vice versa. It helps programmers understand complex C declarations by converting them into a more readable format. It can also be used to generate C declarations from English descriptions, which can be helpful when you need to create a declaration but are unsure of the exact syntax.

cdecl operates interactively; it prompts the user for input, interprets the input as either a C declaration or an English description, and then outputs the translation. It is a valuable tool for both novice and experienced C programmers, as it can simplify the process of working with complex C data types and function signatures. cdecl simplifies the complexity of pointers, arrays, function pointers, and other constructs, by outputting a human readable format.

CAVEATS

cdecl can be confused by certain highly complex or obscure C constructs. Its primary usefulness lies in translating standard, common declarations. It has been superseded in many ways by online tools that provide equivalent functionality with greater ease of access.

USAGE

To use cdecl, simply type 'cdecl' in your terminal. The program will then enter an interactive mode where you can type either C declarations or English descriptions. Type 'help' for additional instructions. To exit, type 'quit'.

EXAMPLES

Example 1: Translating a C declaration.
Type: 'int *(*(*fp1)(int))[10];'
Result: 'declare fp1 as pointer to function (int) returning pointer to array of 10 pointer to int'

Example 2: Generating a C declaration.
Type: 'declare foo as array of 5 pointer to int'
Result: 'int *foo[5]'

HISTORY

cdecl was initially developed to assist in understanding the syntax of the C programming language. It has been available on various Unix-like systems for a considerable time, though specific development history is difficult to pinpoint. Its primary usage has been as a learning tool and a quick reference for C declaration syntax.

SEE ALSO

cpp(1), gcc(1)

Copied to clipboard