

How to understand non-trivial declarations in C. (right-left rule) - dolvlo
http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html
A big thanks to the best professor I had in undergrad for making this.
======
X-Istence
This website has helped me out on various occasions to figure out what was
going on: <http://cdecl.org/> (it won't say if something is illegal though or
not)

~~~
colanderman
Note also the Unix tool of the same name (cdecl).

------
Peaker
FTA:

    
    
      First, symbols.  Read
    
         *		as "pointer to"			- always on the left side
         [] 	as "array of"			- always on the right side
         ()		as "function returning"		- always on the right side
    

If all of these type operators were on the right side, there would be no need
for such a guide. Parenthesis would never be necessary for type declarations,
and they could be read in one direction.

It's unclear why C authors chose to have both prefix and postfix type
operators.

Similarly, the value-level dereference operator could be post-fix, avoiding
the need for (->), and making it much easier to dereference and subscript
array pointers. That would make it feasible to pass arrays by pointer-to-
array, allowing to feasibly pass them by value and have simpler and more
consistent language semantics.

------
program
I use the well-known "clockwise spiral rule"
<http://c-faq.com/decl/spiral.anderson.html>

------
nitrogen
Though I absolutely dislike the excessive use of typedefs (e.g. Windows with
its use of DWORD_PTR instead of unsigned long * or uint32_t * ), I think it's
appropriate to use a typedef or two to simplify declarations of function
pointers which themselves accept or return function pointers.

~~~
gaius
Oracle OCI does this, but it's clear why: Oracle has supported some 90
platforms over its long history, many of which no longer exist, or are no
longer supported, and it's not inconcievable that more will be supported in
future. So instead of char* you say OraText* (for example, there are loads of
these) and for that you get Oracle's guarantee that your code will compile
everywhere Oracle runs.

~~~
nitrogen
It does makes sense for multi-platform software that predates C99's precisely-
sized integer types. I first got my taste of them through a rough predecessor,
the u32/i32/etc. types in the Linux kernel. I see them as a much more
transparent approach to portability for system-level software, but concede
that higher-level software may wish to preserve more meaning in some its type
names (as in your example of OraText vs char). This still doesn't excuse
DWORD_PTR, IMO :).

------
T_S_
An update that includes blocks would be nice.

~~~
CountHackulus
This is a guide for C, not C-like languages. This does not apply fully to
Objective-C, and even C++, especially C++11.

~~~
schrototo
Blocks are a C language _extension_ , they're not unique to Objective-C.

------
prabhat246
Wow, I wish I knew it earlier!! Thanks

