Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!uunet!microsoft!bobatk From: bobatk@microsoft.UUCP (Bob ATKINSON) Newsgroups: comp.std.c++ Subject: Re: casting "const" to "non-const" Message-ID: <56233@microsoft.UUCP> Date: 1 Aug 90 18:32:09 GMT References: <56159@microsoft.UUCP> <56163@microsoft.UUCP> <1913@ux.acs.umn.edu> Reply-To: bobatk@microsoft.UUCP (Bob ATKINSON) Organization: Microsoft Corp., Redmond WA Lines: 41 In article <1913@ux.acs.umn.edu> hopper@ux.acs.umn.edu (Nils McCarthy) writes: >In article <56163@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes: >>Proposed: >> >>That when a parameter [including the hidden "this" parameter] is declared >>"const", or when the object referenced by a parameter is declared "const", >>than it is not legal to modify that which is declared "const" within the >>function. [...] > I don't agree with the illegalization of this construct. I think it >is against the spirit of the language to illegalize a cast. > > In C, and C++ a cast is supposed to always work, no matter what >object you're casting. This is not true of C or C++. Examining Section 5.4 of E&S reveals the following: "Any type conversion not mentioned below and not explicitly defined by the user (Section 12.3) is an error. Any type that can be converted to another by a standard conversion (Section 4) can also be converted by explicit conversion and the meaning is the same." Pointer to integer casts are valid, subject to restrictions. Integer to pointer casts are valid, subject to restrictions. Pointer to pointer casts are valid, subject to rectrictions. Object to reference casts are valid, subject to restrictions. That's it. In particular, for example, casts of floats to pointers or of one object of user-defined type to one of another UDT in the absence of appropriate user-defined conversions is an error. Bob Atkinson Microsoft