What's wrong with this?
devstudio complains about a missing subscript or some nonsense.Code:
double coslu[8][] = 0;
How do I fix it.
Sensible suggestions only please
Printable View
What's wrong with this?
devstudio complains about a missing subscript or some nonsense.Code:
double coslu[8][] = 0;
How do I fix it.
Sensible suggestions only please
The array needs to have a fixed size. For instance:
LaitinenCode:double coslu[8][8] = {0.0}; //initialize all elements to 0.0
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
I'm not defining an array.Quote:
Originally Posted by laitinen
Quote:
Originally Posted by c94wjpn
ok mind telling us what you're trying to do?
you are defining a pointer to an array of pointers.Quote:
Originally Posted by Ultimate Hammer
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.
Trying to define a pointer to a 2d array which has a stride of 8.Quote:
Originally Posted by Ultimate Hammer
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?Quote:
Originally Posted by c94wjpn
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.Quote:
Originally Posted by Hermit
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:Quote:
Originally Posted by c94wjpn
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.Code:double q[][8] = { {0.0}, {0.0}, {0.0} }; // okay, first dimension is 3
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.Quote:
Originally Posted by Hermit
I'm not creating an array. I'm creating a pointer to a memory block.
I think I shall take my problem elsewhere.
So why did you post this:Quote:
Originally Posted by c94wjpn
?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 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.Quote:
I'm creating a pointer to a memory block.
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.Quote:
I think I shall take my problem elsewhere.
Regards,
Paul McKenzie
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)
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.
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?