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:19:27 -0700 Organization: None to speak of Lines: 37 Message-ID: References: <1d52aa30-c145-4131-85cd-1ea3d29b9f74@googlegroups.com> <20170320145406.3450ff4b89d97fb3520ae753@gmail.com> <29025096-4841-4d93-8510-3549682e946f@googlegroups.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="U2FsdGVkX19PYgtCn3KNi2LwHwX/0BFD" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:nzBQYB7RSbkqlyCyGTwGRMbUWxc= sha1:hxC27lCDt1wZAJUS3ccX5G+Abk0= Xref: csiph.com comp.lang.c:106680 already5chosen@yahoo.com 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). [...] > I'd formulate it shorter: Keith's comment is a good example of extreme > legalism far removed from real life of programming in C in general and > from programming in C for embedded systems in particular. How so? uint8_t, uint_least8_t, and uint_fast8_t are all defined in the same header. Why use one that imposes more guarantees than you need? (Of course if you actually need those guarantees, you should use uint8_t.) -- 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"