Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > typedef and pointers.

Thread Tools

typedef and pointers.

David Thompson
Posts: n/a
On Fri, 12 Dec 2008 17:24:19 -0600, Removed) (blargg)

> 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.



> 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?>

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
function template overloading and typedef in GCC Arkadiy Vertleyb C++ 5 09-27-2003 12:28 PM
A question about typedef and classes and templates.. JustSomeGuy C++ 1 09-20-2003 04:33 AM
typename, typedef, and resolution Gina Yarmel C++ 4 08-13-2003 04:06 PM
typedef and #ifdef F. Edward Boas C++ 1 08-11-2003 05:52 PM