Why does a C string gets differently encoded on a Windows and a Linux machine?
First, this is not a Windows/Linux (Operating Systems) issue, but a compiler one as compilers exist on Windows that encode like gcc (common on Linux).
This is allowed by C and the two compiler makers have charted different implementations per their own programing goals, MS using CP-1252 and Linux using Unicode. @Danh. MS's selection pre-dates Unicode. Not surprising that various compilers makers employ different solutions.
5.2.1 Character sets
1 Two sets of characters and their associated collating sequences shall be defined: the set in which source files are written (the source character set), and the set interpreted in the execution environment (the execution character set). Each set is further divided into a basic character set, whose contents are given by this subclause, and a set of zero or more locale-specific members (which are not members of the basic character set) called extended characters. The combined set is also called the extended character set. The values of the members of the execution character set are implementation-defined. C11dr §5.2.1 1 (My emphasis)
strlen("ö") = 1
strlen("ö") = 2
"ö"
is encoded per the compiler's source character extended characters.
I suspect MS is focused on maintaining their code base and encourages other languages. Linux is simply an earlier adapter of Unicode into C, even though MS has been an early Unicode influencer.
As Unicode support grows, I expect that to be the solution of the future.
char
units needed depends on the encoding of the source file. (And, you have to always tell the compiler what the source encoding is or use what it deems the default.) So, it's not up to the system, it's up to you and your source code editor. – Spelter