home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!ames!agate!dog.ee.lbl.gov!horse.ee.lbl.gov!torek
- From: torek@horse.ee.lbl.gov (Chris Torek)
- Newsgroups: comp.lang.c
- Subject: Re: semantics of "<=" change in ANSI C?
- Date: 26 Jul 1992 01:17:54 GMT
- Organization: Lawrence Berkeley Laboratory, Berkeley
- Lines: 34
- Message-ID: <24898@dog.ee.lbl.gov>
- References: <24365@dog.ee.lbl.gov> <1992Jul8.185753.13780@chinet.chi.il.us> <24686@dog.ee.lbl.gov> <1992Jul20.155649.7791@chinet.chi.il.us>
- Reply-To: torek@horse.ee.lbl.gov (Chris Torek)
- NNTP-Posting-Host: 128.3.112.15
-
- In article <1992Jul20.155649.7791@chinet.chi.il.us>
- les@chinet.chi.il.us (Leslie Mikesell) writes:
- >... maybe I just have a broken compiler since it seems to handle constant
- >initializers differently than the same values at runtime.
- >
- >For example:
- >#include termio.h
- >main()
- >{
- >unsigned short a = ~CBAUD;
- >....
- >}
- >gives me an error "initializer does not fit: -16" unless I add a
- >cast, but moving the assignment to runtime does what I expected
- >even without a cast. Is that normal?
-
- If the error is merely a warning, the compiler may still conform to
- the ANSI C standard. If it stops compilation, the compiler is broken.
- Assignment to an unsigned causes truncation modulo some power of two,
- the exact power depending on the maximum value for variables of that
- unsigned type, so even
-
- unsigned short a = -16;
-
- is legal, setting a to 65520 on typical current machines.
-
- In this particular case, a warning is probably a disservice, although
- there may be counterexamples. (For instance, under the BSD
- implementation of POSIX termios, the c_cflag field has type `unsigned
- long'. On the other hand, the BSD implementation has no CBAUD: tty
- baud rates are just integers, as they should always have been.)
- --
- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 510 486 5427)
- Berkeley, CA Domain: torek@ee.lbl.gov
-