0

I am dealing with basically a bit-flag search mask and I'm using vectors. These indexes need to go up to the max integer on the machine (defined in stdint.h)

Basically the problem is

searchMask[ UINTMAX_MAX] = false; // or any value > unsigned int

results in the following warning

warning: C4244: 'argument' : conversion from 'uintmax_t' to 'unsigned int', 
possible loss of data

I have considered just using something like an unsigned char* = "1110010..." and just flipping the bits that way, but dealing with C-strings is always a pain and I suspect accessing the char array index will have this same size problem?

Can I make the indexes of the vector go off the uintmax_t, or should I go the C string route, or what?

y2k
  • 65,388
  • 27
  • 61
  • 86
  • You have a vector of `UINTMAX_MAX` elements _in memory_? – jogojapan Feb 25 '13 at 04:55
  • But that must have gotten you into trouble at a much earlier point, e.g. when running `resize()` or whatever you did to make it larger..? – jogojapan Feb 25 '13 at 04:57
  • The call to resize is what alerted me to this warning. – y2k Feb 25 '13 at 04:59
  • I am afraid you just can't have a vector that large -- it would be larger than your (virtual) memory anyway. Vector indices use `std::size_t`, which apparently is `unsigned int` on your system. `uintmax_t` is a larger data type on your system. There is no way you can use that. – jogojapan Feb 25 '13 at 05:02
  • Also, `UINTMAX_MAX` is a synonym for `UINT64_MAX`. If you're on a 32-bit system, this is larger than `size_t`. – Anthony Feb 25 '13 at 05:04
  • @anthony-arnold Why did you delete your answer? I was just going to upvote it. – jogojapan Feb 25 '13 at 05:09
  • @jogojapan A bit trigger-happy. The whole answer is kind of moot, seeing as having an array that big is brain-damaged. Anyway, I put it back. – Anthony Feb 25 '13 at 06:46

1 Answers1

3

Practically all the STL containers will use size_t as their size types. So, depending on your system, size_t might be defined as an unsigned int, which will probably be a 32-bit integer in your case. That would explain why the compiler is complaining.

UINTMAX_MAX is defined as UINT64_MAX, so it won't fit in a 32-bit integer. Try using the UINT32_MAX macro, or be platform-independant and use std::numeric_limits<size_t>::max().

Also, try using std::bitset<N>.

Anthony
  • 12,177
  • 9
  • 69
  • 105