0

I like/hate linters so I figured I'd try clang-tidy with all the checks turned on and see how I'm doing and how I can improve. Aside from stylistic or non-applicable rules, I hit this call:

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void *)0);

which triggers C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [google-readability-casting] so I fixed it with a static_cast<void *>(nullptr) with the nullptr for good measure. Then I naively "fixed" the next one:

glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), static_cast<void *>(3 * sizeof(float)));

which is an actual error because you can't cast an unsigned long to void *. Fair enough, my bad. I figured an unsigned long was a good candidate for a reinterpret_cast, and so I did, and it compiled fine and ran fine, except that C++ Core Guidelines say do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast].

Short of dynamic_cast, which is a bit silly here, what are my options here?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Morpheu5
  • 2,610
  • 6
  • 39
  • 72
  • 4
    `3 * sizeof(float)` is an integer (type `size_t`), why do you want to cast it to a pointer? – mch Dec 14 '21 at 14:41
  • 3
    Because the function needs a `const void *` as a parameter: `void glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void * pointer)`. – Morpheu5 Dec 14 '21 at 14:43
  • 4
    `glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), nullptr);` should be fine. I don't see a reason for a cast. – mch Dec 14 '21 at 14:43
  • @mch so, in your opinion, `nullptr` is equivalent to `3 * sizeof(float)`? – Morpheu5 Dec 14 '21 at 14:45
  • 6
    You should use the reinterpret_cast as mentioned in anonther topic: https://stackoverflow.com/questions/58679610/how-to-cast-an-integer-to-a-void-without-violating-c-core-guidelines The guidelines are not a law but as said a guideline. Guidelines don't always apply to each circumstance. – Andreas Brunnet Dec 14 '21 at 14:46
  • @AndreasBrunnet Yes thank you, that answers my question. – Morpheu5 Dec 14 '21 at 14:48

0 Answers0