Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!princeton!allegra!alice!shopiro From: shopiro@alice.UUCP Newsgroups: comp.lang.c++ Subject: Re: Constant expressions Message-ID: <6426@alice.uUCp> Date: Fri, 5-Dec-86 09:44:13 EST Article-I.D.: alice.6426 Posted: Fri Dec 5 09:44:13 1986 Date-Received: Fri, 5-Dec-86 21:18:21 EST References: <1252@cit-vax.Caltech.Edu> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 30 Summary: SUN's illegal casts can be eliminated with no effect. In article <1252@cit-vax.Caltech.Edu>, jon@oddhack.Caltech.Edu (Jon Leech) writes: > > I recently found that C++ (1.1) does not allow integral casts in > constant expressions in some cases; for example, > > typedef enum { one = (unsigned)1 } ENUM; > > Unfortunately, this makes it impossible to include some of the graphics header > files on Suns which use this form (it also happens to disagree with > the ANSI C draft, sadly). Has anyone got a fix for this problem? This code (or any code that uses casts in constant expressions) is not legal C according to Ritchie* or the ANSI draft. Apparently some C compilers will accept it; I believe there are others that won't. C++ has already abandoned complete upward compatability with legal C -- it's unreasonable to expect it to be compatible with illegal C. I grant that it is clear what such casts would mean if they were legal, and that there are examples where they might allow you to write code that couldn't be written as directly otherwise. I am confident that if this extension were approved by the ANSI committee it would also appear in C++. However, in all the SUN header examples I have looked at, the cast is pure noise and can be eliminated with no effect whatsoever. That is what I suggest you do. (When you're done, I'm sure there will be many people who would like a copy). * Dennnis Ritchie, The C Programming Language - Reference Manual Sep. 1980.