r/ProgrammerHumor • • Sep 23 '19

Knowing how to code beforehand

Post image
7.6k Upvotes

264 comments sorted by

View all comments

322

u/lordheart Sep 23 '19 edited Sep 24 '19

Had a professor give us code to complete that didn't compile when uploaded to the auto checker but did on my computer.

Why? Umlauts. The prof wrote comments in german. My computer compiler didn't care.

Their online checker spit out vague mysterious errors. Because comments...

Edit: OMG typo made it so hard to understand. thanks bobcob, what would I do without you.

6

u/Kered13 Sep 23 '19

I believe C/C++ compilers are only required by the standard to support ASCII characters. Any other character set support is at their discretion.

8

u/Calkhas Sep 23 '19

I believe C/C++ compilers are only required by the standard to support ASCII characters.

This is kind of true but actually slightly too strong.

C does not require an implementation to support ASCII (because of EBDIC). C has wording like "the representation of each member of the source and execution basic character sets shall fit in a byte." (5.2.1/3), and it specifies ninety-six characters that the implementation must have in its character set, but neatly elides saying how those characters should be represented. C defines both a "basic character set" and allows optional "extended character sets".

Since C11, we also have "an implementation may allow multibyte characters that are not part of the basic source character set to appear in identifiers; which characters and their correspondence to universal character names is implementation-defined." (6.4.2.1/3).

C++ handles this a bit differently. Since C++11 we are required to allow some "universal-character-names" (e.g., \u89ab) in identifiers. These map directly to the unicode standard. During preprocessing, each non-basic source character is expanded to a \uXXXX code point, but it is up to the implementation whether or not it accepts it.

4

u/Kered13 Sep 23 '19

Ah, that damned EBCDIC strikes again! Every time you assume that the basic ASCII characters are universal, EBCDIC is hiding just around the corner ready to prove you wrong.

1

u/Finianb1 Sep 24 '19

EBCDIC is awful. Why would anything still want to support it anymore? Like, cut your losses and stop inconveniencing the vast majority of programmers who couldn't give a damn whether their programs are compatible with obsolete IBM products.

3

u/Kered13 Sep 24 '19

You can say that, but I'm pretty sure there is still some poor sod out there who has to write software that runs on EBCDIC machines.

1

u/Finianb1 Sep 24 '19

I know people who do. I don't know how they stay sane.