EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: 741 on June 26, 2022, 03:49:45 pm

Title: Checking specifier distribution over variable list declaration using cdecl.org
Post by: 741 on June 26, 2022, 03:49:45 pm
I typed this into the box at https://cdecl.org/ (https://cdecl.org/)

static int a, b;

It reports "syntax error". Where is my mistake - is this really illegal C code, or maybe this is not what the cdecl site is for?

Note: I'd actually wanted to double-check a point about the way specifiers distribute over comma-separated variable declarations.
The link I was looking at which relates to this point is here https://stackoverflow.com/questions/55786769/are-all-keywords-distributed-for-comma-separated-variable-definitions (https://stackoverflow.com/questions/55786769/are-all-keywords-distributed-for-comma-separated-variable-definitions)

Title: Re: Checking specifier distribution over variable list declaration using cdecl.org
Post by: golden_labels on June 26, 2022, 04:21:16 pm
The code is perfectly valid C.

The webapp seems to be, however, a kind of a toy. A contraption meant for entertainment purposes only. Or, if anything beyond that, meant to translate particular subset of complicated C declarations to something “more understandable”.
Title: Re: Checking specifier distribution over variable list declaration using cdecl.org
Post by: edavid on June 26, 2022, 05:09:59 pm
The cdecl site is intended to explain declarations, and I find it helpful for that.  It is not a full C interpreter.  It can only parse a single declaration, not a list.
Title: Re: Checking specifier distribution over variable list declaration using cdecl.org
Post by: SiliconWizard on June 26, 2022, 06:22:13 pm
The cdecl site is intended to explain declarations, and I find it helpful for that.  It is not a full C interpreter.  It can only parse a single declaration, not a list.

Yes, indeed. It works perfectly fine for single declarations and is not meant for anything more than this.
It's not a "toy". It can be useful not just for understanding "complex" declarations as a human, but also to check your own parser/analyzer, if you're implementing one, against tricky declarations. I did use it at some point for that.

The additional point of this site is to show how absurd C declarations can be, if you want to have a laugh, or if you are considering designing a new language and get convinced that the C syntax is flawed for humans.