Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Johannes has already remarked that <code>typedef</code>'ing pointers is not inherently bad, and I agree.</p> <p>Some guidelines, based on my subjective opinion of clarity &amp; maintainability:</p> <ul> <li><p>Generally <em>do</em> <code>typedef</code> function pointer types.</p> <p>Reason:<br> Function pointer declarations can get really messy &amp; unreadable.</p></li> <li><p>Generally <em>don't</em> <code>typedef</code> raw object pointers where the pointer type is not an abstraction (e.g., when you just need a "pointer to <em>T</em>").</p> <p>Reason 1:<br> It's more clear to see <code>Foo*</code> or <code>Foo const*</code> than, say, <code>FooPtr</code>. With the name you have to look up the name to see what it's defined as. Perhaps it's some smart pointer, perhaps it's a pointer to <code>const</code>, whatever; the name makes you needlessly look elsewhere.</p> <p>Reason 2:<br> Some programmers are confused by the combination of <code>const</code> and <code>typedef</code>'ed pointer types. E.g. in Microsoft code I've seen the equivalent of <code>FooPtr const</code> many times, where the programmer evidently thought it meant <code>Foo const*</code>. But it doesn't, it means <code>Foo* const</code>.</p></li> <li><p>Generally <em>do</em> <code>typedef</code> also a raw object pointer when the pointer type is an abstraction, a pointer type that conceivably can be replaced with some other type in the future, like e.g. <code>HANDLE</code>.</p> <p>Reason: The same as for using named constants: without a proper name a search and replace can change occurrences that mean something else, and can fail to change occurrences that are not expressed in the exact "right" way.</p></li> </ul> <p><em>However</em>, as with nearly all kinds of style, the arguments pro and con are pretty weak, and so the choice in the end boils down to personal preference, coding standards, co-workers' opinions, and so on.</p> <p>Given a free choice the above is generally what I'd choose. But I have deviated from those guidelines/rules in special cases. As with good art, good code is produced by those who know the rules well enough to also know when to break 'em&hellip;</p> <p>Cheers &amp; hth.,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload