Strange Errors with Python-2.2.2

"Martin v. Löwis" martin at v.loewis.de
Sun Dec 22 11:57:47 EST 2002


lemonite wrote:
>>Try changing the last printf() in your program to this:
>>
>>        x = modf(x, &y);
>>        printf("fractional part = %f\ninteger part = %f\n", x, y);
>>
> 
> 
> Well, this change should not make any difference at all since modf()
> returns the fractional part, while as a side effect storing the integer
> part into the object pointed to by its second argument.

So in your original statement, which reads

printf("fractional part = %f\ninteger part = %f\n", modf(x,&y), y);

do you print the value of y before or after modf has modified y?

Answer: This is unspecified in C. So the modification does change the 
meaning of the program: From one with unspecified behaviour into one 
with well-defined behaviour.

Regards,
Martin




More information about the Python-list mailing list