I have a whole bunch of integer constants that are best given in octal
(PDP-1 opcodes). It makes a huge difference in readability and
authenticity
if these can be entered in octal. I haven't found a way to do this. Is
there one?
C# doesn't have octal literals. However, a couple of possible workarounds:
* VB does support octal literals (use "&O" before the number) so you
could define your constants in a VB.NET class and reference them from C#
* Depending on how the literals are to be used, you could just enter
them as hexadecimal literals that read visually as octal (sort of like
BCD) and then have some code that preprocesses them by taking out the
4-bit gaps in the binary values. I think this would work best if you're
using the literals to initialize an array or something like that, but even
if you're using them for named constants, you could "fake it" by instead
defining fields that are preprocessed at run-time (sorry if that sounds
oxymoronic...I hope you get what I mean
).
Using them as named constants, I think you'd have to gain a lot of
readability to justify the hack, since you'd sacrifice the minor
performance gain actual literal constants get you, as well as the
read-only nature of constants, and of course you'd have to have a block of
code somewhere that goes through and does the run-time preprocessing. All
of that's a pain; I would probably just write the hex, and if readability
was an issue I'd include the octal value in a comment next to it.
But for initializing an array, I think even the second method would work
pretty well.
Why you're looking for "authenticity" in source code, especially when
writing PDP-related code in C#, I'm not really clear on. But I'll take
your word for it that that's a desirable goal for some reason.
Pete