My programmer's instinct would say that a character constant in c (eg: 'x') is encoded using the machine character set from the machine on which it is compiled. However, the following exerpt is from "The C Programming Language: ANSI C Edition"
"A character constant is a sequence of one or more characters enclosed in single quotes, as in 'x'. The value of a character constant with only one character is the numeric value of the charachter in the machine's character set at execution time."
Emphasis on the last 3 words.
Can anyone explain why they would say "at execution time". Surely the character value is encoded in the compiled binary (or ELF, A.OUT...) ?
I was wondering, but couldn't come up with any logical explanaition for this, surely K & R knew what they were doing!
You will have to tell the compiler what system you are going to run the program on. It will then choose the proper encoding for the characters.
Of course, default is to run on a system similar to the one running the compiler. In that case the compile time and runtime character sets will be identical.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With