3 ms·
Not sure I follow. > scalars So you would typedef the scalars then? If you don't, then scalars will be the built-in types (which you'd presumably know well) a
by huhtenberg 10y ago
Not sure I follow.
> scalars
So you would typedef the scalars then? If you don't, then scalars will be the built-in types (which you'd presumably know well) and then all other type names will be typedef'ed structs/unions, still making it trivial to recognize them as such.
- Sir_Cmpwn 10y agoYes, I think typedefing scalars is fine. Typedefs are useful for abstracting the underlying storage mechanism for a scalar (so you can i.e. change it on different archictures or in a future release without breakage), not for saving yourself 6 characters of typing.
- eps 10y agoTypedefs are useful for creating short-hand names for otherwise long or complicated type definitions. Saving 7 (6 for 'struct' + space) characters is as good use for typedef as any other.
- falcolas 10y agoYou only have to write each set of seven characters once; yes, typing will require a bit more effort. However, we shouldn't optimize code for the ease of writing, we should be optimizing for the ease of reading. Write once, read many. `struct foo` is a bit more instructive when understanding code than `foo`; at worst, they read the same to someone familiar to the codebase, at best they prevent the need to flip back and forth to the type definitions.
- dTal 10y ago>Typedefs are useful for abstracting the underlying storage mechanism for a scalar (so you can i.e. change it on different archictures or in a future release without breakage), not for saving yourself 6 characters of typing.
- duck2 10y agoYou can just use stdint types. Or is it really better to typedef a CUTE_INT?
- ddevault 10y agoThat's not what I'm talking about. CUTE_INT is stupid, but maybe mylib_error makes sense. It depends on context.
- mbel 10y agoThere are also enums, which are user defined scalar types (although I don't think this fact really affects your argument).