bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strings in GMP need nil-termination


From: Matt Carter
Subject: strings in GMP need nil-termination
Date: Mon, 11 Feb 2002 16:52:15 -0500

This is a feature request, not a bug report.

It would be nice if GMP functions which take strings (e.g. mpf_set_str())
did not require nil-terminated strings.

Some applications manage some strings as references to portions of other
strings.  For example:

struct {
  char *begin;
  char *end;
} ref;
char *expr_str = "1000*30000";
ref.begin = expr_str;
ref.end = expr_str+4;

This helps avoid copying strings in many cases, and helps eliminate
expensive strlen() calls.

Dealing with strings in this way is even more generic, since the case of
nil-termination is merely a simple specialization of the general case.

Applications that do this cannot use the GMP functions which take
nil-terminated strings unless they make copies of the strings before passing
them in (which is costly).

The problem could be solved if the GMP functions which take nil-terminated
strings had sister functions which took non-nil-terminated strings (they'd
take an extra "int length" or "char *end" parameter).  The amount of new
code would be minimal, since the existing functions could be written using
the new ones.

I have already made the necessary additions to the mpf functions.  If you're
interested, I'd be happy to submit those .

Sincerely,
Matthew Carter



reply via email to

[Prev in Thread] Current Thread [Next in Thread]