1

https://github.com/marek-simonik/record3d/blob/master/include/record3d/Record3DStream.h

In this source I see the following parameter notation

        std::function<void(const Record3D::BufferRGB &$rgbFrame,
                           const Record3D::BufferDepth &$depthFrame,
                           uint32_t $frameWidth,
                           uint32_t $frameHeight,
                           Record3D::IntrinsicMatrixCoeffs $K)> onNewFrame{};

What does the $ do ?

  • Most likely a tag for external code preprocessor. – Quimby Apr 08 '21 at 13:25
  • 7
    `$` is just a character valid in an identifier, same as say `A` or `0` or `_`. There's no special meaning. It's rarely used in hand-written code, but is sometimes used in machine-generated code, to avoid conflicts with human-written identifiers. – Igor Tandetnik Apr 08 '21 at 13:25
  • 2
    See here: [Why is it bad to start a variable name with a dollar sign in C++/Java and similar?](https://stackoverflow.com/q/5845299/4408538) – Joseph Wood Apr 08 '21 at 13:26
  • Oh no we're doin powershell now – Timo Apr 08 '21 at 13:26
  • Noting just part of the symbol name. Demo: https://godbolt.org/z/7bs8ncGsG – Marek R Apr 08 '21 at 13:28
  • @IgorTandetnik That's not true. The valid identifier characters are just a-z plus _: https://timsong-cpp.github.io/cppwp/lex.name#nt:nondigit – NathanOliver Apr 08 '21 at 13:31
  • @NathanOliver Indeed, looks like I misremembered. I thought I saw it in the C++ standard, but checking now, it's not there. I must have remembered it from the compiler-specific documentation: [MSVC does allow](https://learn.microsoft.com/en-us/cpp/cpp/identifiers-cpp) the dollar sign in identifiers. – Igor Tandetnik Apr 08 '21 at 13:37
  • Note that the identifier names here are completely irrelevant. They occur inside the function type used as argument to `std::function`. You can remove them entirely, and the code will still compile. – MSalters Apr 08 '21 at 13:37
  • @Igor Tandetnik, an identifier can not start with 0 ( or any number as i recall ) –  Apr 08 '21 at 13:39
  • @LeoAtreides True, though I'm not sure I quite see how this fact is relevant to the issue at hand. – Igor Tandetnik Apr 08 '21 at 13:40
  • @Igor Tandetnik Insomuch that the $ is the first character of the identifier in the question –  Apr 08 '21 at 13:47
  • @LeoAtreides Well, `$ != 0`, so I still fail to grasp the relevance of your comment. – Igor Tandetnik Apr 08 '21 at 13:48
  • @Igor Tandetnik "$ is just a character valid in an identifier, same as say A or 0 or _", thats not true in general and its not true with respect to the question, as in "$frameWidth" is an allowed indentifier whereas "0frameWidth" is not. –  Apr 08 '21 at 13:54

1 Answers1

1

This is an extension from your compiler to allow $ inside identifiers.

The dollar sign is part of the variable name.

There have been discussions in the committee to prohibit that, but I don't think it has materialized yet.

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
  • With "prohibit", do you mean change it from "Undefined behavior, diagnostic not required" to "Ill-formed, diagnostic required" ? – MSalters Apr 08 '21 at 13:36
  • @MSalters Some members want `$` to be a unary operator for reflection. Right how the reflection proposal uses `^` as unary operator specifically because compiler allows them as an extension. – Guillaume Racicot Apr 08 '21 at 13:37
  • @Guillaume Racicot Although its off topic, I would go with the $ opposed to the ^ seeing as ^ ia already an operator ( XOR ). –  Apr 08 '21 at 13:46
  • @GuillaumeRacicot: I love the idea of ^ being used as it will completely mess up Microsoft's CLI extension. – Bathsheba Apr 08 '21 at 13:47
  • 1
    @Bathsheba And what, pray, is the CLI extension ! ( way off topic now !! ) –  Apr 08 '21 at 13:50
  • @LeoAtreides: Pretty much a scaled down version of the devil. It was the way of getting C++ to talk nicely to the .NET framework. – Bathsheba Apr 08 '21 at 13:52
  • @LeoAtreides: ^ is used to denote a *managed pointer* in that framework. It has the same arity as * when used as a pointer, so it will wreak havoc with the standard C++ grammar if ^ is used for reflection. You would have thought then that they would want $ but alas $ can be a variable name in MSVC. Oh 'eck! – Bathsheba Apr 08 '21 at 13:59
  • @Bathsheba: Does ^ still XOR contextually ? Many decades ago as a budding games dev I thought XOR was awesome... It would be sadly missed if it left the language –  Apr 08 '21 at 14:03
  • 1
    @LeoAtreides: Indeed ^ is still there as XOR, as is ^= too. You can overload both. We can prove that the grammar can be extended to denote a reflective variable using ^ without breaking standard C++. Just like * can be used for multiplication and as a pointer. – Bathsheba Apr 08 '21 at 14:12
  • 1
    @LeoAtreides Yes many wou,ld go with `$`, but it would break code such as yours. This is litteraly the argument against it. If you want the dollar sign to enable reflection in the future, change your tools, and change your codebase, and tell how it went in the discussion with the committee. – Guillaume Racicot Apr 08 '21 at 14:22