Subj : Re: enumerated variables - how to coerce them to anything else than an Int ? To : borland.public.cpp.borlandcpp From : R.Wieser Date : Wed Oct 12 2005 01:09 pm John F(dot) schreef in berichtnieuws 434c033d$1@newsgroups.borland.com... Hello John, [snip] > > Drats ! That does it ! I'm going to switch to Pascal, or something else. > > *Surely* that language can do everything I can imagine ? :-)) > > So I guess you are not very used to the deeper concepts of C...? No, no really. I absolved a course about standard C many, *many* years ago, and just recently (a few weeks ago) decided to take another look at it. My language-of-choice has been, in the mean time, Assembly. > C can do everything. Yes. You may write your own compiler supporting longs > in enums ;-) [thats worst worst case... actually I'd rather quit my job] Assembly gives you even more freedom (not at al sure if that's actually the case ...) :-)) Actually, I took-on C++ once more because it's a somewhat higher-level language, taking certain low-level stuff outof my hands, > BTW :-) Does Pascal have sth like enums? :o) Currently I would not know. I did take look at Pascal, but that's about the same number of years ago (as my C encounter, in the time of the 286, where memory-usage actually ment something) The above response was, as I'm sure you noticed, ment jokingly. An echo of a, what I regard as a not thought about & reflexoid : "does language X not do that ? why don't you use language Y for it" exclamation (without them realizing that the mentioned problem is mostly just a small part in a larger program) > You don't need to _explicitely_ assign 0. it doesn't change generated code. > It just makes it clearer A good reason, especially when other members in that enumeration do explicitily are assigned certain values. [snip] > ok, then you should stay compatible but here I'd assign these > values explicitely Hmmm ... Currently I'm doing just that, while describing all choices in a remark behind/above/below it. Easy to find back / a direct-available info (no need to search for it) when the member needs another setting. [snip] > Thats called typechecking or typesafety... ? Do you mean that as a feature of the compiler, or a method to be applied by the human ? > Its not forbidden to keep things in mind. The only person that > will see them is the developer anyway... Correct. But it sometimes happens that certain programs will again be looked at many months, if not years later. Anything that can support my (not too exact) memory is welcome :-) [snip] > > Would that not allso mean that unions cannot be used either ? > > Or would the (smaller) Int be aligned differently depending on > > the endianness ? I might be wrong, but I don't think so ... > > Its implementation-defined (that is it depends on the compiler). ??? Would that "it depends on the compiler" not kill portability (of the code) right off ? > The problem rather is that you need longs and not ints. Is this > DEFINITELY the case? I think so. As I mentioned, I'm writing that data into a settings-file, and that settings-file get's read by another program. I can therefore not change the structure of that settings-file : the other program would just choke on it :-) > I'd need more information on the whole system: > > Who fills the structure, who reads it? I & the application-program do, the application-program reads it > Is it filled from a file, a binary one? Yep on both accounts > Who is allowed to change it? User, Developer? Both. The program itself was written as a single-user app. > How are the functions taking it as an argument (a reference to the structure > as an argument) defined ? No idea, as I did not reverse-engeneer the whole executable, just what it wrote to the settings-file > > Pre-processing seem to be more work than > > it's worth > > #Definitely not. (you might use a more dirty structure i > provided the "easier to maintain" way...) It does have a "mnemonic" function (the function defined words are easier to remember *if* the words are choosen well), but it does not have anything in regard to the enmueration's main & descerning feature : being "bound" to a single variable-type. And yes, as Assembly does not have enumerations, and I've used in all those years equates instead. I just hoped I could do something "new" :-) > Its the only help that you have left in your tight C/C++ world. > One usually utilizes it exensively. I (feel the) need to first learn those "tight" methods (giving me a good, solid and thoroughly understood basis to work from), only after that adding tricks to my repertoire ... > I'd even consider a complete redesign of the module (thats > usually better and cheaper than 4 or 5 days of debugging...)! I'm afraid that redesigning of that module would cost me a bit more than those 5 days, or even triple of it :) But thank you for your help, I certainly learned from it. Maybe I should just try to find a newer compiler that does support non-integer enumerations ... That would be the quickest & easiest solution :-) Regards, Rudy Wieser .