3
\$\begingroup\$

When I have non-ASCII characters in my C code, TIO counts them as 1 byte.

For example, the following C program prints 56 music-related characters on the terminal.

Link

TIO reports its length as "96 chars, 96 bytes (SBCS)". I understand "SBCS" as follows:

C never standardized its source code format. I assume this source code uses an unspecified single-byte codepage. So each character counts as a single byte.

However, this is unrealistic — even if I include more than 256 different characters in my source code, it still assumes that each character corresponds to one byte.

For reference, here is corresponding code in Python: link

So when can we use byte count reported by TIO as code score?

  • Always?
  • Only when our source code contains fewer than 256 different characters?
    • Maybe ASCII + 128 other characters?
  • Only when some "official" single-byte codepage can represent our source code?

Someone has recently mentioned that "We've been through this many times", but I couldn't find any discussion on it.

\$\endgroup\$
2
  • \$\begingroup\$ There is no specific encoding in which that program is 96 bytes, and so that program is not 96 bytes. You should not rely on TIO/ATO to generate a bytecount if it says "SBCS", since it doesn't actually know which 256 characters are in the SBCS. I think it might actually be a bug in TIO that it says SBCS for C, since it should only be golflangs that have SBCSs. So, if TIO/ATO says "UTF-8", use that byte count. Otherwise, check to see if there really is an encoding in which it is that bytecount. \$\endgroup\$
    – The Thonnu
    Apr 4, 2023 at 11:42
  • \$\begingroup\$ As another example, succinct Charcoal has a code page and an encoding method for characters outside of its code page but TIO and ATO can't use this input method so you have to just use the original Unicode characters instead which are then miscounted. It does at least have the -l option to report the correct number of bytes, although that's buggy on TIO. \$\endgroup\$
    – Neil
    Apr 4, 2023 at 23:20

1 Answer 1

4
\$\begingroup\$

Take TIO's count with a pinch of salt

Firstly, if the language on TIO explicitly uses UTF-8 e.g. Python 3, then the byte counter is accurate to that encoding.

However, if it lists it as "SBCS" (or even "it's complicated"), then it is up to the answerer to verify their own byte count. Exactly how you do that will depend on the language, but generally speaking, you should identify an interpreter where that set of bytes is accepted and does what is intended.

The reason that TIO does this is that the sheer amount of effort Dennis would have to go through to add explicit byte counters for languages with custom code pages is unreasonable. Given that answers should, in theory, always verify their byte counts before being posted, this compromise is perfectly fine.


If you are interested, there are 495 UTF-8 languages, 174 SBCS, 8 xxd languages, 3 "it's complicated" (7, Orst and Sesos) and 1 language that scores in "nibbles": μ6

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .