Skip to content

Conversation

@define-private-public
Copy link

I was including this on a project of mine where I had -Wall -Wextra -pedantic turned on to clean up any extra warnings. I caught about 4 of them in relation to implicit sign and type conversions. Adding some static_cast<> calls and changing a data type resolved all of the warnings.

For reference, here are the warnings:

ProgressBar.hpp: In member function ‘void progresscpp::ProgressBar::display() const’:
ProgressBar.hpp:29:42: warning: conversion to ‘float’ from ‘unsigned int’ may alter its value [-Wconversion]
         float progress = (float) ticks / total_ticks;
                                          ^~~~~~~~~~~
ProgressBar.hpp:30:26: warning: conversion to ‘float’ from ‘unsigned int’ may alter its value [-Wconversion]
         int pos = (int) (bar_width * progress);
                          ^~~~~~~~~
ProgressBar.hpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < bar_width; ++i) {
                         ~~^~~~~~~~~~~
ProgressBar.hpp:37:29: warning: conversion to ‘unsigned int’ from ‘int’ may change the sign of the result [-Wsign-conversion]
         for (int i = 0; i < bar_width; ++i) {

I was including this on a project of mine where I had `-Wall -Wextra -pedantic` turned on to clean up any extra warnings.  I caught about 4 of them in relation to implicit sign and type conversions.  Adding some `static_cast<>` calls and changing a data type resolved all of the warnings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant