0

I am stuck with a warning on xcode, when I try to use the function of the tesseract package:

ocr->SetImage(im.data, im.cols, im.rows, 3, im.step);

I get a warning:

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

How can I solve the problem?

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39

1 Answers1

1

References: Implicit conversion, What is size_t? and this post.

As documentation says:

Implicit conversions are automatically performed when a value is copied to a compatible type.

In your case, trying int to size_t is also an implicit conversion. The reason why the warning mentions about the precision:

  • size_t is always able to store more numbers than int.
  • While size_t holds always a positive value, int can hold also negatives.

According to these two differences between size_t and int, program assumes that some problems or precision loses can occur in the future.

In your case, you can simply convert your size_t type using static_cast conversion:

static_cast<int>(your_size_t_type_parameter)

Note: Using this method can eliminate your warning but this can cause some loses. For example if your size_t value is very huge.

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39