|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - Manifest constants: why enum instead of invariant?
Picking up and idea which had crossed my mind, and that Oskar Linde briefly mentioned on the const debacle thread (news://news.digitalmars.com:119/fsirc9$2hll$1 digitalmars.com): Why do we need enum instead of invariant to declare manifest constants? (I have the feeling that this has been discussed before in the manifest constants debate but I can't remember it nor find it) An invariant variable offers all the power than enum does for manifest constants. The only difference of enum's manifest constants is that they are not an lvalue (their address cannot be taken). But that's a *restriction*, it's not a useful property. The only possible advantage I see is that of optimization: manifest constants do not take up space. But that *hardly* seems significant: manifest constants are usually numeric, and thus occupy about 2-4 bytes each. Even if they are many, in total they are not going to occupy that much space. A string literal can easily occupy as much space as several manifest constants, and they are likely going to be many string literals abound. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D Apr 27 2008
Bruno Medeiros wrote:Picking up and idea which had crossed my mind, and that Oskar Linde briefly mentioned on the const debacle thread (news://news.digitalmars.com:119/fsirc9$2hll$1 digitalmars.com): Why do we need enum instead of invariant to declare manifest constants? (I have the feeling that this has been discussed before in the manifest constants debate but I can't remember it nor find it) An invariant variable offers all the power than enum does for manifest constants. The only difference of enum's manifest constants is that they are not an lvalue (their address cannot be taken). But that's a *restriction*, it's not a useful property. The only possible advantage I see is that of optimization: manifest constants do not take up space. But that *hardly* seems significant: manifest constants are usually numeric, and thus occupy about 2-4 bytes each. Even if they are many, in total they are not going to occupy that much space. A string literal can easily occupy as much space as several manifest constants, and they are likely going to be many string literals abound. Apr 27 2008
Bill Baxter wrote:Bruno Medeiros wrote:Picking up and idea which had crossed my mind, and that Oskar Linde briefly mentioned on the const debacle thread (news://news.digitalmars.com:119/fsirc9$2hll$1 digitalmars.com): Why do we need enum instead of invariant to declare manifest constants? (I have the feeling that this has been discussed before in the manifest constants debate but I can't remember it nor find it) An invariant variable offers all the power than enum does for manifest constants. The only difference of enum's manifest constants is that they are not an lvalue (their address cannot be taken). But that's a *restriction*, it's not a useful property. The only possible advantage I see is that of optimization: manifest constants do not take up space. But that *hardly* seems significant: manifest constants are usually numeric, and thus occupy about 2-4 bytes each. Even if they are many, in total they are not going to occupy that much space. A string literal can easily occupy as much space as several manifest constants, and they are likely going to be many string literals abound. Apr 28 2008
Don wrote:Bill Baxter wrote:Bruno Medeiros wrote:Picking up and idea which had crossed my mind, and that Oskar Linde briefly mentioned on the const debacle thread (news://news.digitalmars.com:119/fsirc9$2hll$1 digitalmars.com): Why do we need enum instead of invariant to declare manifest constants? (I have the feeling that this has been discussed before in the manifest constants debate but I can't remember it nor find it) An invariant variable offers all the power than enum does for manifest constants. The only difference of enum's manifest constants is that they are not an lvalue (their address cannot be taken). But that's a *restriction*, it's not a useful property. The only possible advantage I see is that of optimization: manifest constants do not take up space. But that *hardly* seems significant: manifest constants are usually numeric, and thus occupy about 2-4 bytes each. Even if they are many, in total they are not going to occupy that much space. A string literal can easily occupy as much space as several manifest constants, and they are likely going to be many string literals abound. Apr 29 2008
Bruno Medeiros wrote:Don wrote:Bill Baxter wrote:Bruno Medeiros wrote:Picking up and idea which had crossed my mind, and that Oskar Linde briefly mentioned on the const debacle thread (news://news.digitalmars.com:119/fsirc9$2hll$1 digitalmars.com): Why do we need enum instead of invariant to declare manifest constants? (I have the feeling that this has been discussed before in the manifest constants debate but I can't remember it nor find it) An invariant variable offers all the power than enum does for manifest constants. The only difference of enum's manifest constants is that they are not an lvalue (their address cannot be taken). But that's a *restriction*, it's not a useful property. The only possible advantage I see is that of optimization: manifest constants do not take up space. But that *hardly* seems significant: manifest constants are usually numeric, and thus occupy about 2-4 bytes each. Even if they are many, in total they are not going to occupy that much space. A string literal can easily occupy as much space as several manifest constants, and they are likely going to be many string literals abound. Apr 29 2008
Don wrote:Bruno Medeiros wrote:Around how many bytes are we talking about here, just to get a concrete idea, does anyone know? I'm not familiar with the windows headers nor their D bindings, although I recently checked some of the windows d headers and there were many manifest constants. But I still don't know if their size would amount to something that significant. If for example, you have a cmd line program that prints one page of it's syntax/usage, just that single string would occupy the same space as 400 manifest constants or more. Apr 29 2008
manifest constants do not take up space. Apr 28 2008
|