Article View: comp.std.c++
Article #2866Re: Stuff C++ needs
From: Jimen Ching
Date: Wed, 06 Dec 1995 16:03
Date: Wed, 06 Dec 1995 16:03
32 lines
2381 bytes
2381 bytes
Kevlin A P Henney (Kevlin@two-sdg.demon.co.uk) wrote: >Why? Given that an important feature of a switch statement is that the >target labels are unique, how do you intend to determine this at compile >time for runtime expressions? The labels are unique because they are intended to be used as constants, just like 'a' or 'z'. Just like you do not change 'a' at run time, you can not (or should not) change my constants either. I guess I should say I want to create my own constant 'literals', and be able to control the size. >Sounds like enums to me -- you've got all the language you need to do the job. I did use enums. I switched to a class because it allows me to control the size. The type I had in mind is used very often. Thus size and efficiency is very important. On many systems (especially 32 bit machiens), sizeof(enum) == 4. But, for my internal_type sizeof(internal_type) == 1. Thus, I can store four times as many data, and yet still have the operators for convience. The only problem was, I no long can use switch statements like I could with enums. I guess if I want speed, I have to use array indexing. But with large number of constants, the array will be large, so I still lose storage space. I just can't win. :) It would be great if the switch could detect that my internal type was actually a 'char' type and base the selection process on that. I'm not sure how complicated the compiler would be to do this. But I think it is possible. Maybe it should be an optional feature in C++. --jc -- Jimen Ching (WH6BRR) jching@aloha.com wh6brr@uhm.ampr.org [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4a3h2q$sdf@news.aloha.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<1231@two-sdg.demon.co.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: jching@aloha.com (Jimen Ching) Newsgroups: comp.std.c++ Subject: Re: Stuff C++ needs Date: 6 Dec 1995 16:03:36 GMT Organization: FlexNet Inc, HAWAII Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4a3h2q$sdf@news.aloha.com> References: <1231@two-sdg.demon.co.uk> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: mango.aloha.com X-Newsreader: TIN [version 1.2 PL2] Content-Length: 1602 X-Lines: 28 Originator: clamage@taumet