2.) SWITCH functions only with numeric logic, as I now think is the
only way it works.
So you need to embed the alpha-numeric logic (comparison) inside a numeric logic (comparison), in C every comparison is
numeric, no matter what.
What kind of alpha-numeric
logic is used ? Can you give specific examples?
Concerning cross-compability at source code level:
only use documented standard elements which behave the
same with all compilers on all platforms (but I think
you already know that).
How far off the wall are you prepared to go? If you
fancy a bit of mathematical amusement, read on.
In the general case, one cannot do so directly. If the
values to be compared are integral then the conversion
is straightforward, but for anything else it's a chore.
Remember that C is very flexible about what it
considers to be an integer. Every char is actually a
shrunken int. But a char followed by a NUL char
constitute a string, which is not an integer.
3.) Based on what I learned from the Watcom
Forum, my intitial
translator algorithim was writtne to simply back-level all
SELECT CASE in BASIC to the crude IF / THEN logic.
This is the most direct translation of SELECT CASE ...
CASE ... END SELECT into C. Just remember to include
the magic word "else", because a SELECT CASE statement
can select no more than one case from the list.
However, if you are prepared for a wild ride try using a hash function and then switch based on the hash value. If your
target strings in your CASE clauses are known at
compile time (this is a requirement/limitation of the
C/C++ grammar) then your converter can do the hashing
for you and ensure that the hash values are unique.
Then your code simply calls the hash function on the
variable and switches on the returned value.
Stout's "snippets" collection:
http://www.snippets.org
Having written all that, I cannot let pass the\ ?
opportunity to point out that you have chosen the
wrong language for your task. PL/I is supported on all
the platforms you have mentioned and its SELECT
statement allows everything BASIC's does and more. For
me, the choice of PL/I would have taken very few brain
cycles.
Another county heard from, Dave!
3.) Based on what I learned from the Watcom
Forum, my intitial
translator algorithim was writtne to simply back-level all
SELECT CASE in BASIC to the crude IF / THEN logic.
This is the most direct translation of SELECT CASE ...
CASE ... END SELECT into C. Just remember to include
the magic word "else", because a SELECT CASE statement
can select no more than one case from the list.
The translator is presently written that way..
However, if you are prepared for a wild ride try using a hash
function and then switch based on the hash value. If your target
strings in your CASE clauses are known at compile time (this is a
requirement/limitation of the C/C++ grammar) then your converter
can do the hashing for you and ensure that the hash values are
unique. Then your code simply calls the hash function on the
variable and switches on the returned value.
The target strings are, in some cases.
Based on that, the simplest
thing to do is throw away the stupidity from the earlier code, at
least in my case,and use numeric logic anyway. Problem solved, at
least if SELECT CASE has at most only a very few numeric steps
between 2 to 4, not 2 to 1000's,inclusive.
There *ARE* places where the comparative string data is *NOT* known at compile time. It actually arises from the data. In fact, identical
data is possible, leading to a first in first out logic that is used. Makes no difference on what happens later, first in logic for
solution is correct.
http://www.snippets.org
bookmarked. Which, my memory seems to recently have flagged, might be
a problem. Either his site or is it Gray's interrupt library site
has recently come back to me as "URL not found error" !
The following I won't snip. It's actually what is critical to the
OS/2 specific part of this thread and .. curiously not, but relevent!
Having written all that, I cannot let pass the
opportunity to point out that you have chosen the
wrong language for your task. PL/I is supported on all
the platforms you have mentioned and its SELECT
statement allows everything BASIC's does and more. For
me, the choice of PL/I would have taken very few brain
cycles.
Did *NOT* realize PL/I is in DOS ??? (!) <- Pup scratching ear
The reason I was plowing ahead toward C++ for OS/2, was that per the
DB2 buy-me, try-me, you'll-love-me, banter, was that it specifically
only noted interface capability, I *THOUGHT* in C++, that, function portability taken into account, was also available in DOS.
Of course, you must understand and be patient with me. Of course, DB2 doesn't run in DOS. But the older level interface programs that
might be set to used DATA that DB2 has made available in disk or comm-linked operations, would still have a fighting chance to
maintain a common-source toolset, even spanning DOS, OS/2, whateverX,
and shudder, if under pain o death I have to do WIN-something ...
The bad thing about the future is that it exists. Sigh, in
programming, a thing of beauty is a joy for never.. ;)
Thank you for the ideas, Mikey goeth back to digging in the books,
sigh!
Yes, it does. Therefore, reducing it to numeric logic isn't quite as
easy as i the comparison could be determined at compile time. That
would be easy (I think!) Simply switch the logic to numeric to start
with and forget text! After all, integer operations are, I guess, at
this level about as fast and efficient as you can get! As a matter of fact, from what littleI know, long integers, in some cases, may be
even as good or better than short ones..
Concerning cross-compability at source code level: only use
documented standard elements which behave the same with all compilers
on all platforms (but I think you already know that).
Oh yes... I'm horribly trying to keep the portability issue in front
of me at all times, but learning is expensive... ;)
Sysop: | digital man |
---|---|
Location: | Riverside County, California |
Users: | 1,043 |
Nodes: | 16 (0 / 16) |
Uptime: | 89:30:37 |
Calls: | 500,953 |
Calls today: | 2 |
Files: | 109,377 |
D/L today: |
1,121 files (199M bytes) |
Messages: | 304,684 |