Quantcast
Channel: Is it a good idea to typedef pointers? - Stack Overflow
Browsing all 16 articles
Browse latest View live
ā†§

Answer by ktb for Is it a good idea to typedef pointers?

In general, no. In specific cases, yes.There are a couple constructs that some other answers alluded to, and that is pointer-only types. There are a couple pointer-only type constructs that come to...

View Article


Answer by dgnuff for Is it a good idea to typedef pointers?

No.It will make your life miserable the moment you mix it with consttypedef foo *fooptr;const fooptr bar1;const foo *bar2Are bar1 and bar2 the same type?And yeah, I am just quoting Herb Sutter's Guru....

View Article


Answer by cmaster - reinstate monica for Is it a good idea to typedef pointers?

My answer is a clear "No".Why?Well, first of all, you simply exchange a single character * for another single character p. That is zero gain. This alone should keep you from doing this as it is always...

View Article

Answer by Jonathan Leffler for Is it a good idea to typedef pointers?

Discussion pitched assuming the language of interest is C. Ramifications for C++ have not been considered.Using a a pointer typedef for an untagged structureThe question Size of a struct that is...

View Article

Answer by Dan Hook for Is it a good idea to typedef pointers?

If you do this, you will be unable to create STL containers of const pSomeStruct since the compiler reads:list<const pSomeStruct> structs;aslist<SomeStruct * const> structs;which is not a...

View Article


Answer by hlovdal for Is it a good idea to typedef pointers?

The purpose with typedef is to hide the implementation details, but typedef-ing the pointer property hides too much and makes the code harder to read/understand.So please do not do that.If you want to...

View Article

Answer by BenoƮt for Is it a good idea to typedef pointers?

Some time ago, i'd have answered "no" to this question. Now, with the rise of smart pointers, pointers are not always defined with a star '*' anymore. So there is nothing obvious about a type being a...

View Article

Answer by Martin York for Is it a good idea to typedef pointers?

It (like so many answers) depends.In C this is very common as you are trying to disguise that an object is a pointer. You are trying to imply that this is the object that all your functions manipulate...

View Article


Answer by Chand for Is it a good idea to typedef pointers?

Typedef is used to make code more readable, but making pointer as typedef will increase confusion. Better to avoid typedef pointers.

View Article


Answer by Sad Developer for Is it a good idea to typedef pointers?

This can help you avoid some errors. For example in following code:int* pointer1, pointer2;pointer2 is not an int *, it is simple int.But with typedefs this is not gonna happen:typedef int* pInt;pInt...

View Article

Answer by dreamlax for Is it a good idea to typedef pointers?

Win32 API does this with just about every structure (if not all)POINT => *LPPOINTWNDCLASSEX => *LPWNDCLASSEXRECT => *LPRECTPRINT_INFO_2 => *LPPRINT_INFO_2It's nice how it is consistent, but...

View Article

Answer by Jonathan Leffler for Is it a good idea to typedef pointers?

The only time I use a pointer inside the typedef is when dealing with pointers to functions:typedef void (*SigCatcher(int, void (*)(int)))(int);typedef void (*SigCatcher)(int);SigCatcher old =...

View Article

Answer by Artelius for Is it a good idea to typedef pointers?

This can be appropriate when the pointer itself can be regarded as a "black box", that is, a piece of data whose internal representation should be irrelevant to the code.Essentially, if your code will...

View Article


Answer by JaredPar for Is it a good idea to typedef pointers?

This is a matter of style. You see this kind of code very frequently in the Windows header files. Though they tend to prefer the all upper case version instead of prefixing with a lower case p....

View Article

Answer by sigjuice for Is it a good idea to typedef pointers?

Not in my experience. Hiding the '*' makes the code hard to read.

View Article


Is it a good idea to typedef pointers?

I looked through some code and noticed that the convention was to turn pointer types likeSomeStruct* intotypedef SomeStruct* pSomeStruct;Is there any merit to this?

View Article
Browsing all 16 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>