Re: Natural size: int



Hallvard B Furuseth <h.b.furuseth@xxxxxxxxxxx> writes:
Keith Thompson writes:
Here's a thought.

Defined a new type declaration syntax:

signed(expr1, expr2) is a signed integer type that can hold values
in the range expr1 to expr2, both of which are integer constant
expressions. This will simply refer to some existing predefined
integer type;
(..snip..)

Go ahead and write up a proposal:-) But check out the SBEIR proposal
first:

Specification-Based Extended Integer Range, Revision 3 (5.1)
(WG14/N459 X3J11/95-060) date 1995-08-25, by Farance & Rugolsky
http://wwwold.dkuug.dk/JTC1/SC22/WG14/docs/c9x/extended-integers/

More ambitious - maybe too ambitious, and with a somewhat different
goal. Turned out to be a lot of tricky issues involved. There was a
lot of discussion about it on comp.std.c and (I think) in the C standard
committee, but in the end it was left out. Don't remember why - too
late and too hairy, maybe.

Looks like I don't need to write up a proposal. 8-)}

C99's <stdint.h> is, IMHO, a great improvement over C90's, well, lack
of <stdint.h>, but the SBEIR proposal is much more general. I like
it.

One suggestion I would have made is to allow a specification of the
required range of a type, rather than just the number of bits. Bit
counts, IMHO, place too much emphasis on the representation of a type
rather than what it's used for. Sometimes I just want to know how
many widgets I can count, not how many bits the computer will use to
count them. Of course, sometimes the representation is important; I'd
advocate ranges *in addition to* the number of bits, not as a
replacement.

Another thing: the syntax for suffixed literals is becoming unwieldy
in C, and more so in the SBEIR proposal. For example, SBEIR proposes
that 456P32U specifies an unsigned 32-bit constant with the value 456.
(I would at least allow an underscore: 456_P32U.) The problem is that
there's an extremely terse syntax that parallels the syntax of integer
type names. Instead, I would have suggested using the actual type
name to specify the type of an integer literal. One way to do this is
to use cast syntax: in C99 <stdint.h> terms, (uint32_t)456. In actual
C99, the type of the literal is determined purely by the literal
itself (int in this case), and the cast specifies a conversion to the
specified type. Instead, a special rule could say that when a numeric
literal is the immediate operand of a cast to a numeric type, the
literal has the specified type rather than the default one. Or a
different syntax could have been introduced (Ada, for example,
distinguishes between conversions and qualified expressions).

Of course, the existing suffixes would still have to be supported.

To get back to some semblance of topicality, I wonder how much of this
stuff could be done within standard C. Certainly a compiler could
provide it as an extension, but that doesn't help anyone trying to
write portable code.

Is it possible to write a macro such that
UNSIGNED_TYPE(1000000)
portably expands to either "unsigned int" or "unsigned long",
depending on which type can hold the specified value? I suspect not.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Systax question in MessageDlg
    ... My question is what is the syntax to use for the buttons. ... TmsgDlgbuttons and TmsgDlgBtn. ... three button message box, use the syntax containing Button1, Button2, ... HelpCtx specifies the context ID for the help topic that should appear ...
    (alt.comp.lang.borland-delphi)
  • Regarding @CESYSGEN...
    ... I have read the following from Microsoft documentation regarding @CESYSGEN ... Specifies a component name, using one of the two following formats: ...
    (microsoft.public.windowsce.platbuilder)
  • Regarding @CESYSGEN syntax.....
    ... I have read the followint from Microsoft Documentation regarding @CESYSGEN ... Specifies a component name, using one of the two following formats: ...
    (microsoft.public.windowsce.platbuilder)
  • Re: ASN.1 "INTEGER"?
    ... I looked up section 18.4 of one of the freely available ITU ... > documents and it only specifies the grammar for writing ASN.1 ... The ASN.1 syntax on its own doesn't tell you what the bytes are going ... Doubtless there's Java code out there, ...
    (sci.crypt)
  • Re: The LOOP macro (was Re: Be afraid of XML)
    ... > The thing that has always bugged me about C's for loop is that the ... Bad things about that diagram: ... expr2 is evaluated, when in fact expr2 is the value tested zero/nonzero ... horizontally as is usual in the syntax; ...
    (comp.lang.lisp)