On 2023-06-14 23:46, Bruno Haible wrote:
-              fprintf (fp, "%u\n", (unsigned int) (((bits ^ (bits - 1)) + 1) 
>> 1));
+              fprintf (fp, "%u", (unsigned int) (((bits ^ (bits - 1)) + 1) >> 
1));

This sort of change relies on undefined behavior in POSIX. In the POSIX shell, a command like A=$(B) requires B to output text, and a nonempty text file must end in a newline.

To avoid this issue the program could use 'fopen (..., "wb")'.

We could just leave things alone, as I don't know of any POSIXish systems that would mishandle files lacking trailing newlines in this situation. However, the "wb" approach" is a bit cleaner.

Reply via email to