Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value Conversion issue: Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int'

I just updated my Xcode's version to 5.1 and this error occurred. I'm using the GPUImage library. Here's a screenshot. Thanks in advance guys!error screenshot

like image 264
SwiftlyNily Avatar asked Dec 12 '22 06:12

SwiftlyNily


1 Answers

size_t (size type) is an integral type for the size of objects (C objects, not Objective-C objects) and types. The size of size_t objects (the number of bits it occupies) depends on the pointer size of the used architecture. The size of int objects (the number of bits it occupies) is independent of that and often smaller. So potentially the assignment of a value of the type size_t to a variable of the type intcan fail, if the value is that big that it fits into a size_t object, but not into an int object.

You can do one of the following:

1 Make the variables bufferHeight and bufferWidth of the type size_t, too.

2 Make the variables bufferHeight and bufferWidth of an integral type that is at least as big as size_t, i. e. long or NSInteger. (It depends on the architecture you use.)

3 The error messages warns you about the fact that the implicit conversion of a bigger into a smaller type will fail, if the value stores in the bigger type cannot be represented by the smaller type. If you are sure that the values (the result of the functions) always fit into an int, make the cast explicit.

int bufferHeight = (int)CVPixelBufferGetHeight(…);

BTW: Please do not post screenshots if the content of the screenshot is text. Copy your code and the error message instead. You can copy & paste error messages.

like image 128
Amin Negm-Awad Avatar answered Mar 23 '23 00:03

Amin Negm-Awad