6

If I have a std::vector<Foo> and want to store its size in a GLuint, my compiler gives a warning that there is possible loss of data.

GLuint size = vec.size(); // "conversion from 'size_t' to 'GLuint', possible loss of data"

How do I correctly do this type of casting? Are there more pitfalls of this kind with for example float to GLfloat?

Martin Ender
  • 2,730
  • 4
  • 23
  • 45
Dragonseel
  • 1,810
  • 1
  • 11
  • 24

1 Answers1

6

Practically speaking, probably not - try printing the size of each type using sizeof. Probably GLuint is 32 bits and size_t is 64 bits - so 32 bits are thrown out; but float and GLfloat are probably both 32 bit IEEE 754 numbers. "Probably" sprinkled above, because technically speaking the sizes of C ints, floats and the float format are compiler dependent, but GL type sizes (and formats) should be standard (see https://www.opengl.org/wiki/OpenGL_Type). Chances are, GLfloat is just typedef'd as a float.

You may be able to turn off this warning in your compiler - I choose to explicitly cast ("GLuint size = GLuint(vec.size())" works) so I am reminded of what's happening.