Implementing cdecl with pycparser

October 18th, 2008 at 11:22 am

cdecl is a tool for decoding C type declarations. It was first first described in K&R2 and since then is part of most Unix/Linux distributions.

Well, since my pycparser project is nearing completion, I’ve decided to implement cdecl on top of it. As pycparser is a complete parser and produces ASTs from ANSI C, I figured this shouldn’t be too complicated.

Indeed, it turned out to be quite simple. The core of the implementation (which you can see here) is a 30-line function that traverses the AST recursively and spits out the explanation.

Here are a couple of sample results:

char *(*(**foo [][8])())[];

=> foo is a array of array[8] of pointer to pointer to function() returning pointer to array of pointer to char

static const char* const cptr[2];

=> cptr is a static array[2] of const pointer to const char

The cdecl is a simple and fun way to experiment with pycparser. It teaches how to explore the AST created by pycparser an traverse it correctly.

Related posts:

  1. Reading C type declarations
  2. Allocating multi-dimensional arrays in C++
  3. Correct usage of const with pointers
  4. pycparser v1.0 is out!
  5. Faking standard C header files for pycparser

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)


generic acomplia purchase cialis overnight delivery cheap acomplia online buy generic clomid buy cialis low price viagra without prescription where to buy cialis lowest price levitra where to buy propecia cheap cialis from canada lasix no prescription viagra without rx cheap accutane tablets viagra online without prescription viagra no rx buying cialis online zithromax viagra in uk free cialis cialis us where to buy acomplia find cialis online buy viagra lowest price accutane prescription buy cheap accutane online cialis buy buy generic cialis online acomplia order propecia online lowest price synthroid synthroid without a prescription synthroid online buy propecia online cheap levitra online where to buy levitra cialis online review synthroid prices cialis generic cialis buy drug buy viagra on line viagra pharmacy cialis for order price of levitra zithromax online where to buy synthroid soma generic generic clomid propecia online stores viagra cheap drug cheap generic soma cialis cheap zithromax online cheap order accutane online purchase zithromax online purchase viagra online buy cheap clomid cheap generic propecia zithromax pharmacy online pharmacy cialis cheapest acomplia cost of cialis no prescription viagra free viagra purchase lasix online cialis from india viagra from india order discount cialis soma online stores find no rx cialis cialis no rx required find viagra without prescription approved cialis pharmacy lasix discount