C++26: A User-Friednly assert() macro

(sandordargo.com)

33 points | by jandeboevrie 3 days ago

8 comments

  • grokcodec 6 minutes ago
    Friedns shouldn't let Freidns post on HN without running spell check
  • omoikane 1 hour ago
    > (assert) doesn't follow the usual SCREAMING_SNAKE_CASE convention we associate with macros

    There are a few things like that, for example:

    https://en.cppreference.com/w/c/numeric/math/isnan - isnan is an implementation defined macro.

    https://en.cppreference.com/w/c/io/fgetc - `getc` may be implemented as a macro, but often it's a function.

  • MontagFTB 1 hour ago
    Putting code with side effects into an assert is asking for trouble. Compile with NDEBUG set and the effects mysteriously disappear! Anything beyond an equality expression or straight boolean should be avoided.
  • nyc_pizzadev 1 hour ago
    The nice thing about assert() is you can just define your own:

    https://github.com/fiberfs/fiberfs/blob/7e79eaabbb180b0f1a79...

    In this case, the ability to see the actual values that triggered the assert is way more helpful.

  • amelius 26 minutes ago
    Shouldn't the preprocessor be fixed, if it trips that easily on common C++ constructs?
    • marginalia_nu 6 minutes ago
      Preprocessor is just doing text transformations on the sources.

      It's not really something that can be fixed, other than moving away from the preprocessor and putting metaprogramming capabilities into the language itself (which C++ has been doing).

    • tom_ 23 minutes ago
      I'm sure the standardization committee are always looking for fresh ideas!
  • semiinfinitely 23 minutes ago
    "C++47: Finally, a Standard Way to Split a String by Delimiter"
  • throwpoaster 27 minutes ago
    assert(spellcheck(“Friednly”));