Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: unsigned int |
| Date | Mon, 01 Aug 2016 09:55:25 -0700 |
| Organization | None to speak of |
| Lines | 49 |
| Message-ID | <ln60rk5szm.fsf@kst-u.example.com> (permalink) |
| References | <unsigned-20160731163521@ram.dialup.fu-berlin.de> <e06rglFmcd5U1@mid.individual.net> <nnn35u$2dd$1@dont-email.me> <nnnnqr$589$1@dont-email.me> <nnnpdf$b3s$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Injection-Info | mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="31318"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zauM21vSzE0Ao6Q0Xt2ss" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:ImzFjXEVh+43bWq06q0QeoC/ksQ= sha1:nU3chXTMzKT72tar8AIsyXSjLk8= |
| Xref | csiph.com comp.lang.c:91500 |
Show key headers only | View raw
David Brown <david.brown@hesbynett.no> writes:
[...]
> Personally, I would rather have have a selection of byte-sized types in
> a language like C. I would like a type "char" which can hold character
> data such as 'a'. But assigning an integer value to a char (without
> appropriate casts) should be an error. I would like a type "byte" which
> represents raw data in memory - "byte *" would be used instead of "void
> *" in C, and also in many cases where "char *" is used. So functions
> like "memcpy" would deal in "byte*" pointers, "malloc" would return a
> "byte*", but "strcpy" would use "char*" pointers. And I would like
> numerical types of byte size. To fit C practice, these might be "signed
> short short int" and "unsigned short short int" (with "signed" being the
> default), though I am sure some people would object to those names.
Apart from the implicit conversion of numeric type to char, that's
pretty much what we have. `char` is the type for (narrow) characters,
`unsigned char` represents raw data, and `signed char` is a narrow
signed integer type.
> But we have what we have in C - it's not going to change. The best we
> can do is write code in a way that minimises the risk of errors - and
> that includes being explicit about using signed or unsigned char when
> using them for numbers.
Agreed.
As for uint8_t and int8_t, you should use those only if you need
*exactly* 8 bits. If you just want a narrow integer type of *at least*
8 bits, you can use unsigned char and signed char -- or
[u]int_(least|fast)8_t, depending on your requirements.
[...]
> One should, of course, rely on CHAR_BIT == 8 without ensuring a clear
> compile-time failure if that is not the case. That might be done by
> testing CHAR_BIT and issuing a #error directive - but IMHO it is good
> enough to simply make use of uint8_t and int8_t types.
I presume you omitted a "not" there.
On the other hand, it's reasonable to assume CHAR_BIT == 8 if your code
already relies on POSIX features. (The same probably applies to the
Windows API.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: unsigned int "Osmium" <r124c4u102@comcast.net> - 2016-07-31 12:40 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 11:01 +0200
Re: unsigned int James Kuyper <jameskuyper@verizon.net> - 2016-08-01 10:15 -0400
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 09:59 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 17:21 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-01 09:55 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 22:42 +0200
Re: unsigned int supercat@casperkitty.com - 2016-08-01 14:18 -0700
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 13:11 -0500
Re: unsigned int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-01 19:46 +0100
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-01 18:20 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-02 10:18 +0200
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 09:35 -0500
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-02 08:00 -0700
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 11:12 -0500
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-02 17:11 +0200
Re: unsigned int Les Cargill <lcargill99@comcast.com> - 2016-08-02 11:55 -0500
Re: unsigned int supercat@casperkitty.com - 2016-08-02 10:16 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 14:02 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-03 08:58 -0700
Re: unsigned int James Kuyper <jameskuyper@verizon.net> - 2016-08-02 13:57 -0400
Re: unsigned int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-08-02 19:30 +0100
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-02 11:38 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 14:12 +0200
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-03 13:45 +0200
Re: unsigned int Keith Thompson <kst-u@mib.org> - 2016-08-01 12:02 -0700
Re: unsigned int David Brown <david.brown@hesbynett.no> - 2016-08-01 23:01 +0200
csiph-web