C++ pointer syntax problems -


i professional software developer i'm largely unfamiliar c++ syntax. trying compare value @ end of pointer double in inherited c++ project.

the following bit of code grabs valueaddress text file , prints, example

|"primary key value"|123.456| 

where 123.456 value of double @ address in text file.

... char debugstring[64]; int valueaddress; fscanf(inputfile, "%s %d", key, &valueaddress);//inputfile declared elsewhere printf("|"); printf(database->primarykey);// defined elsewhere , not focus of question printf("|"); sprintf_s(debugstring,64,"%g",* ((double *)valueaddress));  printf(debugstring);      printf("|"); ... 

why then, can't access value using:

if ((double *)valueaddress < -0.5) {...}  

as error "error c2440: '>' : cannot convert 'double' 'double *'"

i can't do:

if ((double) *valueaddress < -0.5) {...}  

as error "error c2100: illegal indirection". creating variable , trying assign doesn't work either.

valueaddress integer in text file, memory address of double value. need use int valueaddress double pointer. works when putting value in debugstring, why won't work in if statement? how can around this?

i'm misunderstanding syntax here. have got wrong?

using int represent address of double stored somewhere , attempting cast int double* undefined behaviour in c++.

an int might not large enough hold pointer address. on 64 bit system, 32 bit int not sufficient.

you might away using intptr_t represent address, , cast using *(double*)valueaddress. it's still not well-defined.

i'm willing corrected on point think realistic choice inline assembly solution specific platform effect conversion. said, you're reading data text file, , can using normal c++.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -