'What is causing this Point-to-Object Error in C?
So I have defined
#define SYS_LEN 50.0
#define N_CELLS ((int)SYS_LEN)
as well as
extern double *array_one
which I populate via
array_one[0] = 0.5*SYS_LEN
array_one[1] = 0.25*SYS_LEN
I then go onto define function
void function(void)
{
int is, ix;
double X;
for (is = 0; is < MAX_VALUE; is++){
for (ix = 0; ix < MAX_VALUE_TWO; ix++)
{
X[is] = 0.5 + (double)ix - array_one[is]
}
}}
However I get an error stating 'expression must have pointer-to-object type'. Not too sure why this is, any help would be appreciated
Thank you
Solution 1:[1]
There are potentially multiple problems.
Potential problem one is you say you allocated memory for
extern double *array_one
and assigned two values. But did you declare enough memory for array_one, and initialize with values, to account for the maximum loop index in your function, which is MAX_VALUE ? If not you would get an access violation if you didn't assign enough memory.
Problem two is definite - it is that you declared a double scalar with double X, but attempted to access it as though you had declared an array.
Assuming you had defined MAX_VALUE as an integer > 1, the solution would be to declare an array of doubles for X:
For example if you had somewhere done
#define MAX_VALUE 20
the corresponding code would need to be
void function(void)
{
int is, ix;
double X[MAX_VALUE];
for (is = 0; is < MAX_VALUE; is++){
for (ix = 0; ix < MAX_VALUE_TWO; ix++)
{
X[is] = 0.5 + (double)ix - array_one[is];
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
