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.
int Nos
- missing the semicolon.con
- this variable is not declared before use.sensor
is not a memeber ofstruct Con
.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 theTTXY
double pointer array.
Note:
- Normally you should follow the standard form of the
main
function but not defined your own version.The normal version ofmain
function should beint main(void)
orint main(int argc, char *argv[])
. - You should include <stdlib.h> to make gcc happy enough not to give you any warnings.
精彩评论