From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a6fe9ef21ba269dc X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe01.iad.POSTED!1d9d5bd3!not-for-mail From: David Thompson Newsgroups: comp.lang.ada Subject: Re: Ada Smileys in C++ lib Conversion Organization: Poor Message-ID: References: <1a9b39b0-73f6-497c-a8f4-abf8129886ac@t20g2000yqa.googlegroups.com> <9b88e5a4-c588-4997-ad5c-2efa216fe4f4@a4g2000prm.googlegroups.com> <95tc66hjv3stdk0nhdv9o46e5l2ecdog5j@4ax.com> X-Newsreader: Forte Agent 3.3/32.846 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 24 Aug 2010 10:11:33 UTC Date: Tue, 24 Aug 2010 06:12:04 -0400 Xref: g2news1.google.com comp.lang.ada:13691 Date: 2010-08-24T06:12:04-04:00 List-Id: On Tue, 17 Aug 2010 12:57:11 +0000 (UTC), Warren wrote: > Maciej Sobczak expounded in news:be7c80ac-3fce-4779-8542- > 115567f649de@g17g2000yqe.googlegroups.com: > > > On 16 Sie, 16:54, Warren wrote: > > > >> > const int MC_CTL_LOCAL_C �= 0x80; > >> > and so on. > > > >> Another approach is to declare them as enums. But this > >> is unhelpful because they are all implemented as int's. > > > > No. Enums are separate types. > > They are considered different "types" but (in C at least), > they're implemented as ints. IOW, you can't mix the enums > but you can supply an enum in an int argument. > Yes but no but yes. In C all enum _constants_ are exactly type '(signed) int' (and within that specific type's range) and an enum _type_ is represented as _some_ supported integer type (like int or short) sufficient to cover the range of constants declared. Most compilers just use 'int' for all enum types, since it is always sufficient, but this isn't required; at least on some targets GCC has -fshort-enums and attribute((packed)). An enum value in most expressions has applied the 'default promotions' which convert it to an integer type (almost always signed int), and a (reasonable) integer value can be assigned or passed by value to any enum. But the types are not formally 'compatible' and e.g. pointer to enum foo is not implicitly convertible to or from pointer to int. C++ makes some changes. First, enum constants can be 'long' and (thus) types up to that, although on some machines that's not actually wider than 'int'. Second, enums convert _to_ integer but not the reverse and not one enum to another, and constants are of enum type not int (or long). Thus e.g. void bar(int x) and void bar(enum foo x) are distinguishable for overloading. > >> Further, the switch statement doesn't tell you about the > >> cases which are missing. > > > > Try g++ -Wswitch. > or slightly stricter -Wswitch-enum . and gcc also. (Or more exactly GCC for both C++ and C, because gcc and g++ are actually drivers that can compile either -- and other supported languages like Ada too; the main difference is which language(s) they can *link*, and at link time compiler-warning settings are no longer applicable.) > GCC extension. Try it on HP or AIX C compiler. > Indeed.