Compiler version: 08.2017
Although character constants written in hex normally may result in portability problems, some utilities need such facilities. For example, I recently had to write a program on the mainframe acting as a HTTP client talking to a web server, and the answers are in ASCII code (or UTF-8), and so the parsing of the HTTP header involves some looking for X'0a' etc.; even on the mainframe.
Or: if you want to define code tables, that is: char arrays with constant initializers, hex notation is very convenient.
I added X'hh' and B'bbbbbbbb' as another possibility to specify character constants; you may add underscores to improve readability (for example to separate 4 or 8 bit groups in longer constants).
Some versions earlier, 0xhhhh has already been added as another notation for integer constants.
Now there are several problems or pitfalls:
- a program containing a mixture of "normal" character constants and "hex" character constants in a case statement (for example) will probably not compile on all platforms
- same goes for set constants or other expressions involving range expressions
Please look at the following example:
|
This will not work on an ASCII machine, because the two case labels '1' and x'31' are obviously the same, but only in ASCII. On an EBCDIC machine, the expression 'A' .. X'45' will not work, because the internal value of 'A' is much higher than X'45'. You will get syntax error on both platforms.
In a future release, the compiler will give warnings on mixed uses of normal and hex or binary notation of char constants that may lead to portability problems.
I hope that I discovered all places in the compiler where character constants are relevant; please feel free to contact me if you detect any errors introduced by this extension. Thanks in advance!