Closed gth828r closed 2 years ago
To test this out, I used the example listed in the quickstart page: https://serizba.github.io/cppflow/quickstart.html
When compiling that example program without any changes, I see the following warnings:
$ g++ -std=c++17 -o main.out -I /usr/local/include/ -I/home/vagrant/cppflow/include/ main.cpp -ltensorflow -Wall
In file included from /home/vagrant/cppflow/include/cppflow/cppflow.h:9,
from main.cpp:2:
/home/vagrant/cppflow/include/cppflow/model.h: In function ‘std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> cppflow::parse_name(const string&)’:
/home/vagrant/cppflow/include/cppflow/model.h:146:21: warning: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘int’ [-Wsign-compare]
146 | return (idx == -1 ? std::make_tuple(name, 0) : std::make_tuple(name.substr(0, idx), std::stoi(name.substr(idx + 1))));
| ~~~~^~~~~
/home/vagrant/cppflow/include/cppflow/model.h: In member function ‘std::vector<cppflow::tensor> cppflow::model::operator()(std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, cppflow::tensor> >, std::vector<std::__cxx11::basic_string<char> >)’:
/home/vagrant/cppflow/include/cppflow/model.h:154:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, cppflow::tensor> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
154 | for (int i=0; i<inputs.size(); i++) {
| ~^~~~~~~~~~~~~~
/home/vagrant/cppflow/include/cppflow/model.h:170:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
170 | for (int i=0; i<outputs.size(); i++) {
| ~^~~~~~~~~~~~~~~
/home/vagrant/cppflow/include/cppflow/model.h:189:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
189 | for (int i=0; i<outputs.size(); i++) {
|
With my changes, the program compiles without these warnings and it still runs.
Thanks, this looks nice!
This change fixes compiler warnings about comparing signed and unsigned types. To see these warnings when compiling with
g++
, you can use the-Wall
flag. Note that in projects which also make all warnings errors (i.e. the-Werror
flag ing++
), these changes are necessary for programs that use cppflow to compile at all.This addresses issue #142