← Back to context

Comment by camgunz

5 months ago

This isn't responsive to what I wrote:

> and yielding a bespoke bignum format is just as unusable as simply returning whatever's encoded in CBOR. How would I add two such values together? How would I display it? This is what bignum libraries are for.

I know this is what you've been getting at. Maybe I've been unclear about why this isn't useful, but here are the main points:

- Without bignum functionality, your data structure doesn't provide any more functionality than memcpy. How do I apply the base? How do I apply the exponent? How would I add two of them together? This may as well just be a `char *`.

- Speaking of just being a `char *`, CBOR's bignums are just that, so you'd just call `mpz_init_set_str` on whatever is in the buffer (zero terminate it in a different buffer, I guess, whatever). Parsing into your struct here is counterproductive.

- Even the minimal functionality you're proposing here is added bloat to every application that doesn't care about bignums and wants to ignore the tag (probably almost all applications). Ameliorating this requires conditional compilation.

> In practice many bignums are just left as is.

I'd believe this; I'd also believe there's very little real need for them generally. This is an argument for not including them in a data serialization format.

> By the way, sscanf is fine here

The problem with sscanf isn't that it can never be safe, it's that if you're not safe every time you blow everything up. It's better to just not use it.