2

In one of the files of the Direct X Samples "MiniEngine" ( https://github.com/Microsoft/DirectX-Graphics-Samples/tree/master/MiniEngine ) I found this line that confused me:

void CameraController::Update( float deltaTime )
{
    (deltaTime); // <-- here
    …
}

At first I thought it was something to make the compiler stop complaining about an unused parameter, but it is used further down anyway. I can only think it is some sort of performance optimisation somehow, but I can't think what.

Can anyone enlighten me? It could always be a new C++ thing I don't know about :) I haven't played with C++ for about 10 years.

AaronHolland
  • 1,595
  • 1
  • 16
  • 32
  • Can you link the exact file and line? Maybe the commit history would have some explanation? – Anmol Singh Jaggi Apr 23 '19 at 05:12
  • [https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/CameraController.cpp#L58](https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/CameraController.cpp#L58) – AaronHolland Apr 23 '19 at 05:14
  • Most likely they don’t use the given argument so this is to make warnings of unused arguments go away – Sami Kuhmonen Apr 23 '19 at 05:15
  • 1
    @SamiKuhmonen: But that would result in another warning in GCC at least: `:5:6: warning: statement has no effect [-Wunused-value]` – P.W Apr 23 '19 at 05:18
  • The whole file was added in [this](https://github.com/Microsoft/DirectX-Graphics-Samples/commit/63384e3af458cede33d292d6252c3ea661365f79#diff-9cc16b5481f1b77735defc3cbd6786c4) commit. So commit message has no hints. – Anmol Singh Jaggi Apr 23 '19 at 05:29

1 Answers1

2

As you wrote, it may be used to mute warnings about unused variable, however it would be better if it was written:

(void) deltaTime;

That should mute warnings on most (if not all) compilers.

Diodacus
  • 663
  • 3
  • 8
  • It's possible that it's a remnant of when the code was not yet completed. As it is now, it gets used further on in the function anyway. – AaronHolland Apr 24 '19 at 03:59