Re: No idea how to fix abs arguments in nanopolish (original) (raw)


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]



Andreas Tille andreas@an3as.eu wrote:

Hi,

to fix bug #853568 I tried a patch (gcc-7.patch) to fix abs() arguments in nanopolish[1] but I have no idea how to deal with this:

... g++ -o src/hmm/nanopolish_pore_model_set.o -c -g -O2 -fdebug-prefix-map=/build/nanopolish-0.5.0=. -fstack-protector-strong -Wformat -Werror=format-security -g -O3 -std=c++11 -fopenmp -Wdate-t src/common/nanopolish_variant.cpp: In function 'std::vector extract_variants(const string&, const string&)': src/common/nanopolish_variant.cpp:32:69: error: call of overloaded 'abs(std::__cxx11::basic_string::size_type)' is ambiguous size_t difference = std::abs(reference.size() - haplotype.size());

The result of subtracting two size_t's is still a size_t, which is unsigned. So you need to cast it to a signed type. The correct type is ptrdiff_t.

http://en.cppreference.com/w/cpp/types/ptrdiff_t

The line then becomes

size_t difference = std::abs(static_cast(reference.size() - haplotype.size()));

Or you could do it in two lines

ptrdiff_t diff_signed (reference.size() - haplotype.size()); size_t difference = std::abs(diff_signed);

Cheers, Walter Landry


Reply to: