Strange behaviour when passing values from a float array to a double array (C, C++) -
i developing application uses ni-daq , below methods given provider.
void somemethod(calibration *cal, float myarray[], float result[]) { newmethod(&cal->rt,myarray,result,cal->cfg.tempcompenabled); } void newmethod(rtcoefs *coefs, double myarray[],float result[],bool tempcomp) { float newmyarray[6]; unsigned short i; (i=0; < 6; i++) { newmyarray[i]=myarray[i]; } }
i call somemethod(), providing array 6 elements ( [6] ) both myarray[] , result[]. can see in code, afterwards newmethod() called, , float myarray[6] passed double myarray[] argument (i not understand why developer of code chose use double array, since array declared inside newmethod() float type).
now here comes problem: inside loop, values passed without problem, when fourth , fifth values passed newmyarray[], receives "-1.#inf0000" both values. @ first glance, thought garbage value, "-1.#inf0000" there @ every execution.
i know c language can tricky sometimes, not know why happening...
the second parameter newmethod
has type double *
. pass value of type float *
.
in c++, or in c if there prototype of newmethod
in scope, must generate compilation error. there no implicit conversion between pointer types , except void *
.
however, in c, if there no prototype in scope may no warning; undefined behaviour @ runtime because function called arguments of different type (after default argument promotions) defined.
if there non-prototype declaration of newmethod
in scope no warning; if there no declaration @ in c89 code legal (i.e. warning optional) , in c99 must warn newmethod
called without being declared.
(so important whether c program or c++ program).
if in c , getting no warning, add prototype before this:
void newmethod(rtcoefs *coefs, double myarray[],float result[],bool tempcomp) ;
then compiler error.
Comments
Post a Comment