Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By RichardS
#86906 Why does i=12;Serial.printf("d=%d\n", i / 10); print out "d=1"

and i=12; Serial.printf("f=%f d=%d\n", i / 10, i / 10); prints out "f=0.000000 d=1073421916", I understand why the %f is not working but why is the %d now affected?? I would still expect d=1 or to the point "f=0.000000 d=1"

RichardS
User avatar
By RichardS
#86908
RichardS wrote:Why does i=12;Serial.printf("d=%d\n", i / 10); print out "d=1"

and i=12; Serial.printf("f=%f d=%d\n", i / 10, i / 10); prints out "f=0.000000 d=1073421916", I understand why the %f is not working but why is the %d now affected?? I would still expect d=1 or to the point "f=0.000000 d=1"

RichardS


I now suspect when the printf does its thing behind the scenes its taking the %f treating it as a double putting that in memory where it is 8 bytes long then placing the 4 byte int next to it and pointing to both.... as opposed to a 4 byte float and 4 byte int which will align to the pointers it calculated.... so somehow the int ends up shifted 4 bytes.... wonder why this never bit me before?? :-)