Error: comparison between signed and unsigned integer expressions [-Wsign-compare]

939 views
Skip to first unread message

Jim

unread,
Apr 19, 2018, 4:27:45 AM4/19/18
to or-tools-discuss
Hi all, 

When building an or-tools program in C++ on Linux, using the binary distribution, I obtain a lot of signed/unsigned mismatch errors. Here is an example of one:

../or-tools/ubuntu-16.04/include/ortools/util/tuple_set.h: In member function ‘void operations_research::IntTupleSet::InsertAll(const std::vector<std::vector<long long int> >&)’:
../or-tools/ubuntu-16.04/include/ortools/util/tuple_set.h:343:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < tuples.size(); ++i) {
                     ^hier op...


My full error log output is here.

Why are all these mismatches in the code? Does it not matter? I was surprised to see that no question was asked about this yet on this group, so I'm curious what other people think about this.

Laurent Perron

unread,
Apr 19, 2018, 5:35:59 AM4/19/18
to or-tools-discuss
Really, it does not matter :-) The code is safe.
And changing i to size_t will create more risk if we use it in some arithmetic operation.

--Laurent
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim

unread,
Apr 19, 2018, 8:30:00 AM4/19/18
to or-tools-discuss
Okay thanks, that is good to know. Then I might need to suppress the errors. Because everytime I build my project 200 of these errors come by.
-Jim

Op donderdag 19 april 2018 11:35:59 UTC+2 schreef Laurent Perron:

Jim

unread,
Apr 20, 2018, 7:06:39 AM4/20/18
to or-tools-discuss
Wouldn't it be better to loop using auto though?

Op donderdag 19 april 2018 14:30:00 UTC+2 schreef Jim:

Laurent Perron

unread,
Apr 20, 2018, 3:28:12 PM4/20/18
to or-tools...@googlegroups.com
Nous, it would use size_t in its place, and we are back to the dangerous unsigned arithmetic. 

Writing x -y with unsigned is error prone. 

--Laurent
Reply all
Reply to author
Forward
0 new messages