3 ms·
File descriptors are an example of such a type. In good code they are carefully kept equal to -1 when not open, and are carefully identified, and not leaked. W
by ncmncm 5y ago
File descriptors are an example of such a type. In good code they are carefully kept equal to -1 when not open, and are carefully identified, and not leaked.
When something has reference semantics but isn't an actual pointer, that is an extra fact that the reader of code needs to know in order to reason correctly about it. That is, thus, a burden above what would be needed for an actual pointer. It is a burden that is harmful to impose entirely unnecessarily.
- Koshkin 5y agoPointers aren't special, and memory is not the only resource that requires managing.
- ncmncm 5y agoPointers are special. They have implicit conversions, and a wide variety of pre-defined operations, typically only a few of which are correct for any particular use. Managing any resource is trivial with destructors. If you need to manage a resource, a pointer is a poor way to do it. In C, you have a poverty of choices, but people are anyway used to being careful around pointers.