How to understand C++ type declaration using cdecl

Type declarations in C or C++ can sometimes look confusing. cdecl is a commandline tool that can convert a type declaration into plain English that might be easier to understand.

To install cdecl:

$ sudo apt install cdecl

To use cdecl:

$ cdecl explain "const int* ip;"
declare ip as pointer to const int

To use cdecl in interactive mode:

$ cdecl
Type `help' or `?' for help
cdecl> explain const int* ip;
declare ip as pointer to const int
cdecl>

Note that I found that cdecl fails on even simple declarations which are legal in C or C++:

$ cdecl explain "const int const * ip;"
syntax error

The cdecl can also be used online here.

Tried with: Cdecl 2.5-13 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s