Skip to content

Fix sign conversion issues #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fix sign conversion issues #7

wants to merge 1 commit into from

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