lkml.org 
[lkml]   [2000]   [Jan]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: time_t size: The year 2038 bug?
Johan Kullstam" <kullstam@ne.mediaone.net>
>i'd also like to see C types with *specified* bit widths, e.g.,
>int16, int32, uint8 &c. then you could write more portable code when
>you really need a certain number of bits like for CRC algorithms. in
>case of 36bit computing on a pdp-10 the compiler could at least
>complain about lack of 32 bit support (even if it would be easy to
>add) instead of silently failing.

I think an even more flexable definition would work better:

int var : 4; /* integer data, 4 bits wide. */
int var2 : 36; /* integer data, 36 bits wide */
int crc : 64; /* integer - 64 bits */
int bigcrc : 128; /* integer - 128 bits */
int strange : 22; /* integer - 22 bits */

A construct such as this is already permitted (although not to this
level of flexability). It is roughly equivalent to a bit vector, but
having operators of type integer, and extended beyond the largest supported
integer type.

This would also allow for the following:

typedef int hex : 4; /* define an integer type "hex" */
/* containing 4 bits */

then a usage:

unsigned hex i; /* i contains 4 bits unsigned */
hex j; /* j is a signed 4 bit integer */

Of course, the sizeof function has to change. It might be done by having
two forms: bitsizeof() and sizeof(). The sizeof function returns the
storage requirement of an addressed item in units of bytes. Hence from
the examples: sizeof(var) => 1 - the minimum unit of allocatable storage
for the unit, bitsizeof(var) => 4.

Variables with non storage unit sizes could be packed only in a data
structure. Pointers to non storage unit sized data items could be valid
if the item is not in a structure. This could be relaxed if the structure
had a "unpacked" attribute, but this might make it too difficult for
portability reasons.

This also drops the need for things of type "long" and "long long". You
would be able to do:

typedef int long :64;
/* I would let int default to 32 bits */
typedef int short :16;
typedef int byte :8;
typedef int hex :4;
typedef int bool :1;

Trying to get this into an ANSI C definition is very problematical though.
-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:55    [W:0.038 / U:1.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site