Opened 6 years ago

Closed 6 years ago

#852 closed defect (fixed)

Use static_cast to remove conversion warning

Reported by: cvvergara Owned by: cvvergara
Priority: trivial Milestone: 3.7.0
Component: Core Version: 3.6.2
Severity: Unassigned Keywords:
Cc:

Description

From:

https://travis-ci.org/OSGeo/geos/jobs/328675353#L3328

/home/travis/build/OSGeo/geos/src/noding/MCIndexNoder.cpp:154:50: warning: conversion to ‘int’ from ‘size_t {aka long unsigned int}’ may alter its value [-Wconversion]
  si.processIntersections(ss1, start1, ss2, start2);

There are many conversion warnings.

By adding static_cast:

  • Keep the original signatures
  • Shows a clear intent of the original authors of using a specific type.
  • Helps tidy the code
    • C++ is catching type changing see example

Showing intention:

The comments (if any) shows clear intent to the programmer but not to the compiler

Class A {
  /* code here */

  // the user can give me an int and it will be saved on a size_t
  void set_num(int _value) {m_num = _value;}
  // the user will get an int out of the size_t
  int get_num() {return m_num;}
  size_t m_num; 
}

Clear intention is for both the user and the programmer

Class A {
  /* code here */

  void set_num(int _value) {m_num = static_cast<size_t>(_value);}
  int get_num() {return static_cast<size_t>(m_num);}
  size_t m_num; 
}

Change History (4)

comment:1 by robe, 6 years ago

Milestone: 3.7.03.8.0

comment:2 by cvvergara, 6 years ago

Owner: changed from strk to cvvergara

comment:3 by cvvergara, 6 years ago

Changes Already done in master

comment:4 by robe, 6 years ago

Milestone: 3.8.03.7.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.