← 返回命令列表

Linux command

cdecl 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

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

echo "declare argv as array of pointer to char" | cdecl

Define a typedef

cdecl declare "str as typedef pointer to char"

说明

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.

参数

-+
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.

FAQ

What is the cdecl command used for?

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.

How do I run a basic cdecl example?

Run `cdecl` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -+ do in cdecl?

Use C++ syntax instead of C (same as -c).