I was writing some code in C# the other day and it got me thinking. If a char literal can only have 1 char (or a delimited character) then why do we need the closing delimiter?
For example, currently we need to write:
char character = 's';
And there is no circumstance where this can work (obviously):
char character = 'sa';
Then why do we have to put the closing '
rather than have it implied? Eg:
char character = 's;
char anotherCharacter = '\';
Readability would only be impacted because we are used to the current standard (not necessarily because this way is less readable).
In C#, Java and C++ the answer is simple:
Because that's the way it was implemented in C.
Why was it implemented in C that way?
Who knows? There may be some implementation quirk in the first C parser/compiler that made this choice obvious; I'm betting that K&R just didn't think about it. A single quote just looks weird.
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