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:23:29 -0800 Organization: None to speak of Lines: 23 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="11343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1d3bipl8fV1ars8d0j51S" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zytFTRIUirIEQBzzKB52APqmGOk= sha1:4pIrpB01BQs08MNjbSeftLL6Uyk= Xref: csiph.com comp.lang.c:139037 Barry Schwarz writes: > On Mon, 24 Dec 2018 14:03:25 -0800 (PST), chanrasjid@gmail.com wrote: [...] >>So what is the purpose of casting. > > The purpose of a cast is to allow you to force a conversion between > types for which no implicit conversion exists. This is used > frequently for pointers. > > A secondary use is to silence the diagnostic generated by some > compilers when you know the conversion will not cause the problem the > diagnostic is warning you about (e.g., loss of significance or > overflow). It can also be used to control when a conversion is performed, and to what type, even for a conversion that could have been done implicitly. This is most common in numeric expressions. -- 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"