strings that are not null-terminated

Marco Bodrato bodrato at
Mon Nov 12 17:00:33 UTC 2018


Il Ven, 9 Novembre 2018 3:04 pm, Trevor Spiteri ha scritto:
> Currently functions that take strings take null-terminated strings, e.g.
>     int mpz_set_str (mpz_t rop, const char *str, int base);
> To use a substring of a larger string that cannot be modified, I have to
> copy the substring to a new allocation to add a null character at the
> For this use case, it would be convenient to have functions taking
> strings similarly to strncmp, e.g.
>     int mpz_set_strn (mpz_t rop, const char *str, size_t n, int base);

You are right!

A comment in the code, since 2001, agrees with you:

but currently the comment is still there.
Of course, the new allocation is a small cost asymptoticaly... at least
when base is not a power of 2.



More information about the gmp-discuss mailing list