Avoid using variables in an inner scope with the same name as variables in
an outer scope. Enable the -Wshadow compiler flag for C and C++ source
files such that in the future the compiler will complain about shadowing.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
TARGETS := $(C_TARGETS) $(CXX_TARGETS)
-CFLAGS := -O2 -Wall
-CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wno-sign-compare -Werror
+CFLAGS := -O2 -Wall -Wshadow
+CXXFLAGS := -O2 -std=c++11 -Wall -Wextra -Wshadow -Wno-sign-compare -Werror
all: $(TARGETS)
break;
}
}
- ssize_t len = sg_write(fd, offs / block_size, iov);
- if (len >= 0)
- std::cout << "Wrote " << len << "/"
+ ssize_t written = sg_write(fd, offs / block_size, iov);
+ if (written >= 0)
+ std::cout << "Wrote " << written << "/"
<< iov.data_len()
<< " bytes of data.\n";
} else {
- ssize_t len = sg_read(fd, offs / block_size, iov);
- if (len >= 0) {
- std::cerr << "Read " << len
+ ssize_t read = sg_read(fd, offs / block_size, iov);
+ if (read >= 0) {
+ std::cerr << "Read " << read
<< " bytes of data:\n";
- iov.trunc(len);
+ iov.trunc(read);
iov.write(std::cout);
}
}