- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
At least that way, typos become compiler errors.
Admin
Except when they don't. Which, as with most stringified things, will happen quite often.
Admin
Isn't this just the stringy equivalent of this?
Admin
I didn't know a '$' could be used in a variable names in C/C++ (I assume). Last time I saw a '$' in a variable names was in PL1 (circa. 1970's).
Silver start to TDWTF for teaching something new.
Admin
Its a little worse than #defines because this only produces a warning:
const char $$B[] = "$$B"; char *ptr = $$B; *ptr = 'x'; printf("%s\n", ptr);
Admin
There is a benefit to this approach: you can't document strings, but you can document variables.
Admin
That is so true.
In future, I must revise my approach to writing documents. I shall no longer use the deprecated "noun" or "verb" things, which are hideously stringified.
"Variables?" That's the ticket.
Admin
I choose to believe the first three constants are involved in a ridiculously convoluted approach to adding the BEL character to something and the rest was added by people just going along with it.
Admin
Well, at least that won't compile...
Admin
"I didn't know a '$' could be used in a variable names in C/C++ (I assume). Last time I saw a '$' in a variable names was in PL1 (circa. 1970's)."
It can't. A C++ variable name, like a C variable name, can only be letters, digits and underscores, and can't start with a digit. Either their compiler allows nonstandard identifiers or there's something bogus here.
Admin
Ah, it's the compiler. Found this little gem on Microsoft's documentation web site: "The dollar sign $ is a valid identifier character in the Microsoft C++ compiler (MSVC)."
Admin
This isn't as useless as it seems. IDEs and cross-reference tools can find uses of a variable.
Admin
I suspect that it's there to make porting old programs in other languages to C easier since it may eliminate the need to change variable names. Of course, if you use this feature, you've just made your program utterly non-portable, which I expect is not a downside to Microsoft.
Admin
Apparently "$" in C/C++ variable names is legal in many cases: https://stackoverflow.com/a/18033976/11026
Admin
Cool! I'm going to start naming my variables $1000, $1000000, $19999, etc. - and claim my code is worth more!
Admin
Come compilers collapse duplicate literals, some don't. Some compilers have strings with duplicate values point to the same buffer, some don't.....
Admin
(effectively) #warnings as errors...
seriously, my CI/CD pipelines along with my Git commit hocks will refuse to process any project which does not have this set to true. (means of setting and detecting depend on compiler/environment,,,
Admin
That is why "Compliance Mode" should always be turned on. (Note for NERW projects it is on by default, for old projects it is off. Also /sdl should always be on.