New Data Type?

Shawn H. Oesterle oesterle at wpi.wpi.edu
Wed Mar 21 03:19:59 AEST 1990



The following C data types have incremental sizes of 2^n bytes: 
(unsigned) char, short, and long.  Some compilers have data type
called 'long long' which is 64 bits long.  If 128 bit computers
begin to emerge (if not already), we may have what is called a
"long long long", and for 256-bit computers, a "long long long
long", ad infinitum (maybe just have a "very long").  Where do we
stop?  It would be nice to have a user definable size for a
numerical type.  Suppose we call it 'maketype' where the size it
is a multiple of 8-bit data types the quantity has. 

Defining the size of 'maketype' could take place by using the
sizeof keyword as the lvalue.  For example:

void function(maketype mSomewhatBig)  {
     /* mTemporary is an integer value of an undefined size */

     maketype mTemporary;

     /* using a modified version of sizeof, mTemporary is
        assigned the size of mSomewhatBig, which has previously
        been given a definite size */

     sizeof(mTemproary) = sizeof(mSomewhatBig);
     .
     .
     .
}

In this example, it is clear that sizeof(maketype) could be
unknown at compile time:

void func2(int iNumber)  {
     maketype mTemp;

     sizeof(mTemp) = iNumber;
     .
     .
     .
}

The advantages of a user definable size for a data type would
make a particular algorithm less restrictive to a particular data
type size (The problem I am facing and why I am making all this
up in the first place).  So in accordance with my hardly thought
out previous notion on the implementation of 'makesize' we have
following algorithm in a 'maketype' way:

/* compute the factorial of number x */

unsigned maketype factorial(unsigned maketype x)  {
     unsigned maketype tmp=1;  /* temporary result */
     unsigned maketype i;      /* index */

     /* the size for 'i' is defined to be equal to the size of 'x' */
        
     sizeof(i) = sizeof(x);

     for(i=1; i<=x; i++)  {
          tmp *= i;
     }
     return(tmp);
}


Do any programming languages have this ability?

-- 

                                     /^\
"ne zorgas, estu fali<ca!"         <- * ->              Shawn Oesterle
                                     \_/                oesterle at wpi.wpi.edu



More information about the Comp.lang.c mailing list