On Fri, 12 Dec 2008 17:24:19 -0600,
(blargg)
wrote:
> John Bode wrote:
<snip: typedef whatever X, *XPTR; idioms>
> > Personally, I've found that hiding the pointerness of a type behind
> > a typedef causes more problems than it solves.
>
Generally.
> Another problem is that you then need a typedef for a const T* as
> well, for functions that don't modify the pointed-to object.
>
> typedef int foo, *foo_ptr, const* const_foo_ptr;
>
Even worse; you need a whole second declaration:
typedef int foo, *ptr_foo; typedef const foo *ptrc_foo;
/* using an alternate naming style for variety */
although it could be macro-generated using ## pasting.
> Since the latter typedef is usually left off, it discourages
> const-correctness, because it causes callers to be inconsistent:
>
> void modify( foo_ptr );
> void examine( const foo* );
Concur. (Except modify probably ought to have some additional
arguments, and examine usually ought to return something.)
Of course, among people who don't like bothering with const
correctness anyway this isn't considered a problem. <G?>