Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: A final word on casting. Date: Mon, 24 Dec 2018 15:34:57 -0800 Organization: None to speak of Lines: 41 Message-ID: References: <41c52811-03f6-4546-a2d4-fe85d9d27411@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="8745b6ad340556919bae059294b5099a"; logging-data="15713"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kNue7/ShsOXOYfQzvl5Nr" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:Q16FclCORV4o2URsQ/mw2eMtS3k= sha1:iGB5B1J3dBdRf2CWWuXoSyI756M= Xref: csiph.com comp.lang.c:139039 chanrasjid@gmail.com writes: > On Tuesday, December 25, 2018 at 6:39:42 AM UTC+8, Barry Schwarz wrote: >> On Mon, 24 Dec 2018 14:03:25 -0800 (PST), chanrasjid@gmail.com wrote: [...] >> >As C allows for assignment of one type to a variable of a different >> >type, a set of casting rules is needed. So this is C type casting. >> >> A set of conversion rules is needed. > > Yes, yours is the "philosophical" professional explanation of type > casting. Introductory C textbooks does only as found in the internet; > I did not read of such deeper explanations from introductory > textbooks. There's nothing "philosophical" about it, unless you consider the distinction between a correct explanation and an incorrect explanation to be a matter of philosophy. If your introductory textbooks explain this incorrectly, you need better textbooks. Any book that claims that "cast" is synonymous with "conversion", or that there's such a thing as an "implicit cast", was written by someone who doesn't know C well enough to be writing books about it. Another strong indicator of a bad C book is the use of "void main()" as if it were correct. (It's unfortunate that there are a lot of such books out there.) Can you cite the textbooks in question? We'd like to be able to steer people away from them. We can also recommend better books for you. The definitive description of the C language is the ISO C standard. The latest freely available draft of the current standard is http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf It's not written for beginners, but I suggest you grab a copy and see whether it's something you can refer to when you have questions. (Conversions are discussed in section 6.3, cast operators in 6.5.3.) -- Keith Thompson (The_Other_Keith) kst@mib.org Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"