| ▲ | IronFox05 a day ago | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Call me a hater but I don't like the spiral rule and I like "declaration follows use" even less. How do you make an std::array of a given type? Wrap the existing type in an extra layer of std::array, we all know this, it makes sense, there's no reasonable alternative. How do you make a C-array of a given type? Oh boy, "prepend the array specifier before the list of existing array specifiers" (actually it's worse because you have to find the right possibly-empty array of existing array specifiers first, just because there's a list of array specifiers somewhere in the type doesn't mean it's the one you should be prepending to). "Declaration follows use" immediately goes out the window when faced with typedeffed types being used as the base type, or (as mentioned) generics in descendant languages of C. Instead you get "declaration builds up a type by wrapping layers around a core, use breaks down a type layer by layer starting from the outside" (so, necessarily, they mirror each other). C could have worked that way, and it would have made more sense. "Declaration follows use" is the type level equivalent of taking off your socks before taking off your shoes because that's the order in which you put them on. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | clifflocked a day ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> we all know this, it makes sense, there's no reasonable alternative There absolutely are reasonable alternate ways to represent ordered data that don't involve templates. The way that C does it makes sense in most cases, and if you are looking at something that you cannot understand, you are looking at bad code. > "Declaration follows use" immediately goes out the window when faced with typedeffed types being used as the base type Typedefs are an abstraction. If you create a typedef, it is usually because you only want to handle the data as a whole, passing it to helper functions that remove the typedef. Also, declaration of use does not break down with typedefs:
> "Declaration follows use" is the type level equivalent of taking off your socks before taking off your shoes because that's the order in which you put them on.Please give me an example of some C code where this is the case. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | jstanley a day ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> How do you make an std::array of a given type? std::array isn't a thing in C, so you don't. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ▲ | stackghost a day ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
>How do you make an std::array of a given type? Wrap the existing type in an extra layer of std::array, we all know this huh? where is the extra layer?
>How do you make a C-array of a given type? Oh boy, "prepend the array specifier before the list of existing array specifiers"? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||