1

I have the following code in an iOS app, which uses the Accelerate framework:

 NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
            if (radius % 2 != 1) {
                radius += 1; // force radius to be odd so that the three box-blur methodology works.
            }
            vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, radius, radius, 0, kvImageEdgeExtend);

Xcode is showing a warning on the last line:

Implicit conversion loses integer precision: 'NSUInteger' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int')

Can I replace NSUInteger with uint32_t, even though I am converting the rest of this project to 64 and 32 bit safe code (mostly NSInteger instead of int, and the resulting method definition changes).

If not, how do I resolve the issue with NSUInteger?

HenryRootTwo
  • 2,572
  • 1
  • 27
  • 27
  • There's nothing about fixed-size integer types that isn't "64 and 32 bit safe". What hypothetical issue are you worried about? – Stephen Canon Dec 16 '14 at 15:40

1 Answers1

3

You have two options:

  1. Change radius to uint32_t instead of NSUInteger.
  2. If you know that radius will never be too big, cast radius to uint32_t in the call to vImageBoxConvolve_ARGB8888.
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    The best solution is to simply make radius an `uint32_t`; that's fairly safe here because a blur radius of 4 billion pixels is simply not going to happen. If you wanted to be completely safe, you would clamp the double-precision computed value before converting it to integer. – Stephen Canon Dec 16 '14 at 15:36