|
-
October 23rd, 2007, 08:52 AM
#1
2d array pointer
What's wrong with this?
Code:
double coslu[8][] = 0;
devstudio complains about a missing subscript or some nonsense.
How do I fix it.
Sensible suggestions only please
-
October 23rd, 2007, 09:29 AM
#2
Re: 2d array pointer
The array needs to have a fixed size. For instance:
Code:
double coslu[8][8] = {0.0}; //initialize all elements to 0.0
Laitinen
-
October 23rd, 2007, 09:32 AM
#3
Re: 2d array pointer
if youre going to allocate that 2-d array later just do
double coslu** = 0;
if youre trying to initialize all values to 0 then first off you need definite bounds for the array in both dimensions and then you have to loop through and set them all to 0 manually
-
October 23rd, 2007, 09:37 AM
#4
Re: 2d array pointer
 Originally Posted by laitinen
The array needs to have a fixed size. For instance:
Code:
double coslu[8][8] = {0.0}; //initialize all elements to 0.0
Laitinen
I'm not defining an array.
-
October 23rd, 2007, 09:46 AM
#5
Re: 2d array pointer
 Originally Posted by c94wjpn
I'm not defining an array.
ok mind telling us what you're trying to do?
-
October 23rd, 2007, 09:49 AM
#6
Re: 2d array pointer
 Originally Posted by Ultimate Hammer
if youre going to allocate that 2-d array later just do
double coslu** = 0; /// error stars in the wrong place
you are defining a pointer to an array of pointers.
From looking at the memory blocks in a debugger, it is clear that
double coslu1[8][8];
does not create an array of pointers.
hence
double** p = coslu1;
will not succeed.
-
October 23rd, 2007, 09:52 AM
#7
Re: 2d array pointer
 Originally Posted by Ultimate Hammer
ok mind telling us what you're trying to do?
Trying to define a pointer to a 2d array which has a stride of 8.
If I know that my doubles are in a consecutive memory block at location p, and the stride is 8, then the notations
p[y][x]
and
p[y*8 + x]
should be equivalent, and hence I should be able to define
double * q = 0; ///ok
also
double q[][8] = 0; /// not ok.
-
October 23rd, 2007, 10:47 AM
#8
Re: 2d array pointer
 Originally Posted by c94wjpn
Trying to define a pointer to a 2d array which has a stride of 8.
If I know that my doubles are in a consecutive memory block at location p, and the stride is 8, then the notations
p[y][x]
and
p[y*8 + x]
should be equivalent, and hence I should be able to define
double * q = 0; ///ok
also
double q[][8] = 0; /// not ok.
What are you trying to do by assigning it to 0?
An array is not just a pointer, it occupies a space on the stack. So it cannot (or should not) be NULLed, if that's what you're trying to do. If you're trying to initialize all elements of the array to 0, how is the compiler supposed to know how many elements there are if you don't explicitly supply a second dimension?
- Alon
-
October 23rd, 2007, 11:14 AM
#9
Re: 2d array pointer
 Originally Posted by Hermit
What are you trying to do by assigning it to 0?
An array is not just a pointer, it occupies a space on the stack. So it cannot (or should not) be NULLed, if that's what you're trying to do. If you're trying to initialize all elements of the array to 0, how is the compiler supposed to know how many elements there are if you don't explicitly supply a second dimension?
engage your brain please.
I can set a pointer to NULL if I want to - I'm not accessing it yet.
I have explicitly supplied a second dimension :
double q[][8] = 0; /// not ok. THE 8 IS THE SECOND DIMENSION.
sensible responses only
Last edited by c94wjpn; October 23rd, 2007 at 11:16 AM.
-
October 23rd, 2007, 11:58 AM
#10
Re: 2d array pointer
 Originally Posted by c94wjpn
engage your brain please.
I can set a pointer to NULL if I want to - I'm not accessing it yet.
I have explicitly supplied a second dimension :
double q[][8] = 0; /// not ok. THE 8 IS THE SECOND DIMENSION.
sensible responses only
I meant both dimensions. If one dimension is omitted, then the compiler at least needs to be able to deduce that dimension from the initialization list. For example:
Code:
double q[][8] = { {0.0}, {0.0}, {0.0} }; // okay, first dimension is 3
This is only relevant if you're actually aiming at initialization. I don't know what to suggest if you're determined to somehow NULL an array on the stack. It can't be done, and there's no reason to do it.
And please, drop the condescending tone. Your question is vague at best and if you'd like a sensible answer you'd do best to be a little cooperative.
Last edited by Hermit; October 23rd, 2007 at 12:03 PM.
- Alon
-
October 23rd, 2007, 01:11 PM
#11
Re: 2d array pointer
 Originally Posted by Hermit
I meant both dimensions. If one dimension is omitted, then the compiler at least needs to be able to deduce that dimension from the initialization list. For example:
Code:
double q[][8] = { {0.0}, {0.0}, {0.0} }; // okay, first dimension is 3
This is only relevant if you're actually aiming at initialization. I don't know what to suggest if you're determined to somehow NULL an array on the stack. It can't be done, and there's no reason to do it.
And please, drop the condescending tone. Your question is vague at best and if you'd like a sensible answer you'd do best to be a little cooperative.
well I think I've outgrown codeguru. Maybe I should quit.
I'm not creating an array. I'm creating a pointer to a memory block.
I think I shall take my problem elsewhere.
-
October 23rd, 2007, 01:45 PM
#12
Re: 2d array pointer
 Originally Posted by c94wjpn
well I'm not creating an array.
So why did you post this:
Code:
double coslu[8][] = 0;
?
What is that supposed to mean? Tell us in your own words what that is supposed to do or what you thought it would do, if it isn't trying to create an array.
I'm creating a pointer to a memory block.
I see no "*" syntax anywere in the declaration above. So you are not creating a pointer to anything in your initial post. You are doing something with trying to declare an array -- what exactly is still a mystery.
I think I shall take my problem elsewhere.
Unless you explain a little better what you're trying to do, expect the same, if not worse responses from whatever site you take your very vague question to.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 23rd, 2007 at 02:03 PM.
-
October 23rd, 2007, 05:38 PM
#13
Re: 2d array pointer
I think this guy has no idea of what is talking about, that is all. Let him go elsewhere. He probably guilts other people for his ignorance and in his frustration he just pretends to know what is going on, now don't ask me why he made any question in the first place (needs a psicologist's help not a programmer's)
--------------------------------------------------------
--------------------------------------------------------
Some things in life cannot be explained.
--------------------------------------------------------
--------------------------------------------------------
-
October 24th, 2007, 05:45 AM
#14
Re: 2d array pointer
Are you trying to do something like this?
Code:
double coslu[8][8];
double *p_coslu = &coslu[0][0]; // Pointer to the start of the 8x8 block of doubles.
-
October 24th, 2007, 11:14 AM
#15
Re: 2d array pointer
And that would be just like:
double coslu[8][8];
double *p_coslu = coslu;
I'm thinking, guessing from what he wrote on the title he wanted this:
double * P_coslu = &coslu[8][0]; // 2nd array?
--------------------------------------------------------
--------------------------------------------------------
Some things in life cannot be explained.
--------------------------------------------------------
--------------------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|