• can't think of any more stupid names (unregistered)
    const char FRIST  = "FRIST";
    
  • Peregrine (unregistered)

    At least that way, typos become compiler errors.

  • Sole Purpose Of Visit (unregistered) in reply to Peregrine

    Except when they don't. Which, as with most stringified things, will happen quite often.

  • (nodebb)

    Isn't this just the stringy equivalent of this?

    #define ZERO 0
    #define ONE 1
    
  • CrashMagnet (unregistered)

    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.

  • (nodebb) in reply to Steve_The_Cynic

    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);

  • Anonymous') OR 1=1; DROP TABLE wtf; -- (unregistered) in reply to CrashMagnet
    Comment held for moderation.
  • Hanzito (unregistered)

    There is a benefit to this approach: you can't document strings, but you can document variables.

  • Sole Purpose Of Visit (unregistered) in reply to Hanzito

    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.

  • (nodebb)

    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.

  • (nodebb) in reply to can't think of any more stupid names

    const char FRIST = "FRIST";

    Well, at least that won't compile...

  • Conradus (unregistered) in reply to CrashMagnet

    "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.

  • Conradus (unregistered) in reply to Conradus

    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)."

  • Barry Margolin (github)

    This isn't as useless as it seems. IDEs and cross-reference tools can find uses of a variable.

  • Yet Another Old Programmer (unregistered) in reply to Barry Margolin
    Comment held for moderation.
  • Conradus (unregistered) in reply to Barry Margolin

    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.

  • a cow (not a robot) (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Conradus

    Apparently "$" in C/C++ variable names is legal in many cases: https://stackoverflow.com/a/18033976/11026

  • Steve W (unregistered) in reply to bdoserror

    Cool! I'm going to start naming my variables $1000, $1000000, $19999, etc. - and claim my code is worth more!

  • Yikes (unregistered)
    Comment held for moderation.
  • (nodebb)

    Come compilers collapse duplicate literals, some don't. Some compilers have strings with duplicate values point to the same buffer, some don't.....

  • Bob Geary (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Rick

    (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,,,

  • (nodebb) in reply to Conradus

    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.

  • Sauron (unregistered)
    Comment held for moderation.
  • <a href="https://jobsloverz.com/"> Jobsloverz</a> (unregistered)
    Comment held for moderation.

Leave a comment on “Throw it $$OUT”

Log In or post as a guest

Replying to comment #:

« Return to Article