strings that are not null-terminated

Trevor Spiteri tspiteri at
Fri Nov 9 14:04:14 UTC 2018

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
end. Is there a way to avoid this allocation, or is the allocation in
this case considered insignificant because of the time usually taken in
the parsing itself?

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);


Trevor Spiteri

More information about the gmp-discuss mailing list