string coercion works better than hoped

chris hermansen clhermansen@gmail.com
Wed Aug 6 17:32:53 GMT 2025


Hello all,

Recently I stumbled on this article about efficient integer-to-string
conversion:

https://towardsdatascience.com/34-faster-integer-to-string-conversion-algorithm-c72453d25352

and I thought to implement something similar in GNU Algol 68.

I declare a row as

[1:14] char result;

leaving it uninitialized and then building the string representation of the
number left to right.

at the end I forgot myself and just return

string(result)

And what I subsequently realized is that magically trims the result to the
exact length.  In hindsight I would have thought I would need to write

string(result[1:result_length])

instead.  I speculate that this is due to the declaration initializing the
row to nulls and then the string coercion stopping at the first null
detected.

I am not sure I should rely on this behaviour!

-- 
Chris Hermansen · clhermansen "at" gmail "dot" com

C'est ma façon de parler.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/algol68/attachments/20250806/040310b5/attachment.htm>


More information about the Algol68 mailing list