Converting mpz_t to different integer representations
Steve Kargl
sgk@troutmask.apl.washington.edu
Fri Jan 12 19:44:00 GMT 2007
On Fri, Jan 12, 2007 at 08:08:59PM +0100, Paul Thomas wrote:
> In making a patch for PR29786, I have met a problem with converting
> mpz_t variables into a C type of known length len. One way of doing
> this is given in the patch attached to the PR; another is:
(snip code)
> This works fine on the platforms that I am using but I suppose that
> there will be some for which, for example, long long does not exist?
> How do I check for this?
I read PR29786 and must admit I'm confused at what you're trying
to do. AFAIK, trans-type.c defines info for storage:
trans-types.c: gfc_numeric_storage_size = 4 * 8;
trans-types.c: gfc_character_storage_size = gfc_default_character_kind * 8;
You should be able to do
switch (e->ts.type) {
BT_INTEGER:
BT_REAL:
BT_LOGICAL:
switch (e->ts.kind)
{
case 1: len = 8; break;
case 2: len = 16; break;
case 4: len = 32; break;
case 8: len = 64; break;
case 10:
case 16: len = 128; break;
}
}
Of course, you would also need BT_CHARACTER and BT_COMPLEX. For
BT_DERIVED, a recursive function could build up the storage size.
Note to avoid hardcoded numbers here, you can use information
from gfc_real_info, gfc_logical_info, and gfc_integer_info.
--
Steve
More information about the Fortran
mailing list