Skip to content
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

reduce some compile warning #3645

Merged
merged 1 commit into from
Aug 24, 2017

Conversation

jacquesqiao
Copy link
Member

fix #3644

for (int i = 0; i < finalPaths_.size(); ++i) {
for (int j = 0; j < finalPaths_[i].size(); ++j) {
for (size_t i = 0; i < finalPaths_.size(); ++i) {
for (size_t j = 0; j < finalPaths_[i].size(); ++j) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use size_t in for loop: https://google.github.io/styleguide/cppguide.html#Integer_Types

You can write like this:

for (int i = 0; i < int(finalPaths_.size()); ++i) {
  for (int j = 0; j < int(finalPaths_[i].size()); ++j) {
    // ...
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not quit understand why it's not good to use size_t in a for loop. Instead it writes:
When appropriate, you are welcome to use standard types like size_t and ptrdiff_t.

and here has some other explanation.
https://stackoverflow.com/questions/1951519/when-should-i-use-stdsize-t

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can follow this principle:
If you want to traverse a vector or an array with for loop, size_t is acceptable, otherwise use int instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Canpio I think we should not obey google c++ style for this situation.

Because all STL containers are rewritten in google. They make containers' size_type as int. We are using std's containers like unordered_map, vector, which size_type is size_t.

So maybe just use size_t is fine. Using int only has an advantage when reversely access a container,i.e., when uses -- operator.

@jacquesqiao jacquesqiao merged commit 7fdf5c8 into PaddlePaddle:develop Aug 24, 2017
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.

reduce build warning
3 participants