Home > Net >  What is causing this Point-to-Object Error in C?
What is causing this Point-to-Object Error in C?

Time:03-27

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

CodePudding user response:

The problem here is 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

#define MAX_VALUE 20

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]
    }
}}
  • Related