import Numeric
import numpy
a = Numeric.zeros([1, 1])
while True:
a[0, 0] = numpy.int32(0)
Hello, I am LI Daobing(first name is family name). You can talk with me in English or Chinese.
Showing posts with label coder. Show all posts
Showing posts with label coder. Show all posts
2007-05-05
2007-02-11
a trap I met today
the following code:
will crash if a is empty, because a.size() return a size_t, which is unsigned, then a.size()-1 is a very large unsigned value. it should be changed to:
P.S. I does not consider a.size() > 2G, at least it will not happen in this program.
the following code:
vector<int>a;
// init a
for(int i = 0; i < a.size()-1; i+=2) {
// do something;
}
will crash if a is empty, because a.size() return a size_t, which is unsigned, then a.size()-1 is a very large unsigned value. it should be changed to:
vector<int> a;
// init a
for(int i = 0; i+1 < a.size(); i+=2) {
// do something;
}
P.S. I does not consider a.size() > 2G, at least it will not happen in this program.
Subscribe to:
Posts (Atom)