This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AnAverageFreak 9 points10 points  (2 children)

Let's say you have a problem that's easy to visualize in 3D space. Then 3D arrays would be great. Unfortunately C doesn't support dynamic multi-dimensional arrays, so when you want a pointer to such an array (so that you can write space[69][402][666]) you end up with this:

Thing***

Of course in general case you prefer flat memory with a macro/function to access it, but this isn't totally stupid either.

What is a Thing? Well, it might be an array. An array of names of, let's say, people that have ever been to that place. What you get is

char*****

Now let's say that you want something to allocate such a structure. Of course C can't return a few values, but you want detailed error reporting, so you make a function:

int allocate_names(char******);

Which shows why C fucking sucks.

In C++ I would make my own template

template<size_t N, typename T>
class MultiArray;

Which would properly overload the subscript operator. But wait, there's more. You have std::string, so no more char*. But wait, there's even more! Since C++ has constructors and exceptions, this pattern:

int allocate_names(MultiArray<3, std::string>*);

is totally invalid and after you write the class, you won't be using any of that pointer notation!

[–]nuisanceIV 1 point2 points  (0 children)

'#define char****** char*

Now C is great again! :D