Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Array allocated on stack or heap Date: Tue, 21 Mar 2017 08:17:04 -0700 Organization: None to speak of Lines: 49 Message-ID: References: <1d52aa30-c145-4131-85cd-1ea3d29b9f74@googlegroups.com> <20170320145406.3450ff4b89d97fb3520ae753@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="2dce90611c954a97839cf9cb5d391a4e"; logging-data="32674"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18F0WO0fxCaQvGK8MvzgFEL" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:IVp5VLuF5SgFXZImnvuT8KHvaiA= sha1:AGgVnJDEcbbtL0wm/Cnrn4VEpv0= Xref: csiph.com comp.lang.c:106679 David Brown writes: > On 20/03/17 17:02, Keith Thompson wrote: >> already5chosen@yahoo.com writes: >> [...] >>> That's not what I meant. In most places a proper numeric alternative >>> to 'char' is either int8_t or uint8_t. >> >> Using int8_t or uint8_t makes sense only if you need a type that's >> *exactly* 8 bits wide, with no padding bits or trap representations, >> and represented in 2's-complement for int8_t, . int8_t has a range >> of exactly -128..+127. uint8_t has a range of exactly 0..255. Both >> types are almost certain to exist in a C99 or later implementation >> with 8-bit bytes, but they're not guaranteed to exist on all systems. >> >> If you need a narrow numeric type with *at least* a certain range, >> you can use [u]int_least8_t or [u]int_fast8_t, depending on your >> requirements. Or you can use signed char or unsigned char, both >> of which are guaranteed to be at least 8 bits. Or, if all you care >> about is that the range is at least 0..127, you can even use plain >> char (though for such a purpose either signed char or unsigned char >> is likely to be more appropriate). > > That is all correct. So you agree with me. > In /most/ places, if you need a very small numeric > type, then int8_t or uint8_t is the correct type. So you disagree with me. [...] > Yes, there may be occasions when uint_least8_t (or uint_fast8_t) is > appropriate for portability. But I think in the huge majority of > situations where you might want uint_least8_t, then uint8_t would work > just as well - and it is simpler and clearer, and gives you stronger > guarantees. And what if you don't need those stronger guarantees? How often do you care whether a signed type uses two's-complement or not? [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"