2

In MPFR the basic data types are defined as

typedef struct {
  [...]
} __mpfr_struct;
typedef __mpfr_struct mpfr_t[1];
typedef __mpfr_struct *mpfr_ptr;

and functions in the header are using mpfr_ptr, e.g.

void mpfr_init (mpfr_ptr)

but the docs are just using mpfr_t instead

void mpfr_init (mpfr_t x) .

Honestly I think this is misleading, and I actually had some issues with shared_ptrs which I couldn't resolve easily because of this.

My best guess is that MPFR did typedef __mpfr_struct mpfr_t[1] so people can just "blindly" put it into the functions like the docs suggest?! Are there any other reasons not to do typedef __mpfr_struct mpfr_t instead, change the docs to what's in the header and trust people are good enough with simple pointers or am I missing something?

oli
  • 659
  • 1
  • 6
  • 18
  • Does this answer your question? [Regarding typedefs of 1-element arrays in C](https://stackoverflow.com/questions/18560660/regarding-typedefs-of-1-element-arrays-in-c) – Dai Aug 07 '20 at 10:32
  • @Dai: From one of the answers in your link "However, the structure can still be passed to functions that require a pointer type, without requiring the user to convert to a pointer with &bar every time." So this is what I guessed as well in my question. Again I don't think obfuscating what one is dealing with is helping (on the contrary), and I have comments who think similarly. So I might not be missing anything... – oli Aug 07 '20 at 10:37
  • Note that this idea comes from GMP, and MPFR (which is based on GMP and was designed as an extension of GMP to floating-point numbers with well-defined semantics) reused it. So you need to ask the GMP developers (Torbjörn Granlund is probably the one who decided to choose it, as being the initial author, but I'm not sure). – vinc17 Aug 07 '20 at 17:51

0 Answers0