out of curiosity, have you found one?
out of curiosity, have you found one?
By 4x pointer, do you mean something like int ****x? If that's what you mean, you should never run into anything more than two in good code.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
I've seen some pointers like that in tensor mathematics. For example, in mechanics, a stiffness tensor is 3x3x3x3, so often you want to have four subscripts. Although I personally would not use a 4d array, but rather a 1D array and use operator()(int,int,int,int) to index into it.
Last edited by Cat; 11-21-2003 at 01:44 AM.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
I know its horroble programming style, but I just recently found out that you are able to have up to a 13x pointer (int *************x). I'm just asking around to see if anybody has ever found it practical to take advantage of this, because it is pretty useless.
>I'm just asking around to see if anybody has ever found it practical to take advantage of this, because it is pretty useless.
I've found use of up to four levels. I can't think of a situation for many more than that though.
>you should never run into anything more than two in good code.
I like to believe that I write "good code", yet I've used triple pointers quite a few times in non-trivial data structure code.
My best code is written with the delete key.
I can't see any situations where two or less pointers couldn't accomplish the same thing. If you can, please show me.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
>I can't see any situations where two or less pointers couldn't accomplish the same thing.
Let's say that I need to write a function to dynamically allocate a low level matrix of T. Both x and y need to be arbitrary, but the function is required to return a status instead of the pointer itself to meet consistency requirements for the project. In other words:
Now I have no choice but to perform the allocation on my original pointer. The most natural and clear solution is to pass a pointer to the pointer:Code:if ( matalloc ( &matrix, x, y ) != GOOD ) { // Enter error handling code }
With no effort at all I managed to reach three levels of indirection through necessity. Of course, I could use a reference:Code:error_code_t matalloc ( T ***matrix, int x, int y ) { // Allocate memory and return status }
But tell me honestly whether you knew what the syntax was for that without seeing it or testing it. If you did, can you be sure that everyone else will too? *** is very obvious to anyone who understands pointers, but reference syntax can be tricky. The natural reaction is to do this:Code:error_code_t matalloc ( T **&matrix, int x, int y ) { // Allocate memory and return status }
You could also wrap the matrix in a structure to be more obvious:Code:error_code_t matalloc ( T& **matrix, int x, int y )
But we still need to use a pointer or a reference on the structure so you gain only extra complexity with the use of an unnecessary struct and member accesses to it. Some might argue that this has the benefit of clarity since instead of *** all we use is *, but others might respond that it's overkill. You could even use a global variable, but that would be a bad idea in general.Code:struct matrix_s { int **matrix; };
So, while you can think of ways around more than two levels of indirection (I can as well), that isn't the issue. Sometimes we don't have the luxury of doing anything we want due to restrictions of the coding style or project requirements. I don't think that using the best solution within the restrictions given is bad style. If you think otherwise you should consider whether you are being naive.
My best code is written with the delete key.
You can ALWAYS use only two or less pointers, but it may not always be the most intuitive. As I said, I've seen tensors with lots of pointers, although I dunno if I like it much like that.Originally posted by XSquared
I can't see any situations where two or less pointers couldn't accomplish the same thing. If you can, please show me.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
I think tensors and matrices and all such data structures should be wrapped in classes anyway.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law