Boost logo

Boost :

Subject: [boost] [xint] Question about suitability, portability, and "Boostiness"
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2010-04-12 22:57:27


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Right now, the XInt library uses a pointer to a (privately defined)
struct. The struct has several items, including a small array of "quick
digits" and a pointer to a dynamically allocated array of digit_t types,
both for containing the magnitude of the integer.

While trying to find a more efficient way to store things, I came up
with this:

        struct new_data_t {
                size_t used, allocated;
                // (other data items)
                digit_t digits[1]; // Last item in the struct
        };

It's an old C trick, apparently legitimized in the C99 standard as the
"struct hack". For those not familiar with it, the idea is that I'd
allocate a single array of digit_t types, of the required size plus
sizeof(new_data_t), then just typecast it as a pointer of type new_data_t.

Does anyone know if there's any reason not to do this? Maybe some
portability or alignment problem with it?
- --
Chad Nelson
Oak Circle Software, Inc.
*
*
*
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvD3ZQACgkQp9x9jeZ9/wQLdQCgklN2Xcs0mDAGhsy4n3TX/Bgw
JVoAoK+/YEoawXT7Yd0R3++eWLPYZhjr
=Jx8O
-----END PGP SIGNATURE-----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk