cast from ‘stackval*’ to ‘unsigned int’ loses precision (Program Bug and Problems)

by Frédéric Bron, Wednesday, October 31, 2012, 00:35 (1724 days ago)

I am building on fedora 17 with g++ 4.7.2.
I had to apply the following changes to make the program compile. Why casting to unsigned int and dividing by sizeof(stackval)? Any particular reason not to use simple pointer arithmetics?


--- ../toto/Stack.cpp 2012-10-31 01:27:38.046538005 +0100
+++ ./Stack.cpp 2012-10-31 01:27:47.676643384 +0100
@@ -53,7 +53,7 @@
int Stack::height()
{
// return the height of the stack in elements
- return ((unsigned int) top - (unsigned int) bottom)/sizeof(stackval);
+ return top-bottom;
}

void


Complete thread:

 RSS Feed of thread

powered by my little forum