开发者

Dereferencing issue in C

开发者 https://www.devze.com 2022-12-20 22:51 出处:网络
when I try to compile my code below I get the following errors: error C2440: \'>=\' : cannot convert from \'double *\' to \'double\'

when I try to compile my code below I get the following errors:

error C2440: '>=' : cannot convert from 'double *' to 'double'

error C2440: '>=' : cannot convert from 'double *' to 'double'

I believe I'm dereferencing everything correctly

#define TRUE 1
#define FALSE 0;

#include <stdio.h>

typedef struct Con{
  double samTime[2];
  double sen[2];
  int test[2];
} CON, *CON_PTR;

void GM(double **TTXY) {
  int NoS;
  int numOfSen = 2;
  int startTime =0;
  CON con;

  if((con = (CON_PTR) malloc(numOfSen*sizeof(CON)))==NULL) {
    printf(“Malloc failed\n”);
    exit(1);
  }
  for (NoS=0;NoS<numOfSen;NoS++) {
    con[NoS].samTime[0] = startTime;
    con[NoS].samTime[1] = startTime;
    con[NoS].sensor[0] = 0;
    con[NoS].sensor[1] = 0;
    con[NoS].test[0] = FALSE;
    con[NoS].test[1] = FALSE;
  }

  if (con[NoS].samTime[0] >= TTXY[1]) {
    con[NoS].test[0] = TRUE;
  }
  i开发者_运维百科f (con[NoS].samTime[1] == TTXY[1]) {
    con[NoS].test[1] = TRUE; 
  }
}


First, there's a missing semicolon

int NoS

and your main function is not correct, this must be one of

int main()
int main(int argc, char **argv)
void main() // not standard but allowed by some compilers (with warning)

and as to your question, no you're not dereferencing it right, as your TTXY array is 2-dimensional. So it should be something like

if (con[NoS].samTime[0] >= TTXY[1][some other number]) {

whatever works for your code. And you should use more descriptive names for your variables if others are supposed to understand the code.

If TTXY should really be a one-dimensional array, then you don't need to pass it by reference (function(&TTXY)), passing the pointer value (function(TTXY)) will be enough and more readable.


TTXY is declared as double **, so TTXY[1] is double *, not double, so you cannot compare TTXY[1] with con[NoS].samTime[0].

I guess may be you have a typo in function head, try modifying it to void main(double *TTXY)?


Why does your main function have the signature

(int)(double**)

To be a valid C program, main must have the signature:

(int)(int, char**)

If you want main to process its arguments in another way, then you need to convert them on your own.


There is four syntax errors in your program.

  1. int Nos - missing the semicolon.
  2. con - this variable is not declared before use.
  3. sensor is not a memeber of struct Con.
  4. TTXY is a pointer to pointer to double not point to double,so you should use *TTXY[1] to acess the first double point by the first double pointer in the TTXY double pointer array.

Note:

  1. Normally you should follow the standard form of the main function but not defined your own version.The normal version of main function should be int main(void) or int main(int argc, char *argv[]).
  2. You should include <stdlib.h> to make gcc happy enough not to give you any warnings.
0

精彩评论

暂无评论...
验证码 换一张
取 消