我有一个size_t
变量,我会在NSLog
. 此变量包含发送的字节数。
如果我使用这个:NSLog(@"%zu",myvariable);
我没有错误消息,但数字溢出并且 NSLog 输出一直显示低于 32.768 的数字。这是为什么?Long 不应该显示从 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 的值吗?
这是一些代码。我想在 NSlog self.bufferOffset 中显示,这应该是发送的大约字节数。
// If we don't have any data buffered, go read the next chunk of data.
if (self.bufferOffset == self.bufferLimit) {
NSInteger bytesRead;
bytesRead = [self.fileStream read:self.buffer maxLength:kSendBufferSize];
if (bytesRead == -1) {
[self stopSendWithStatus:@"File read error"];
} else if (bytesRead == 0) {
[self stopSendWithStatus:nil];
} else {
self.bufferOffset = 0;
self.bufferLimit = bytesRead;
}
}
// If we're not out of data completely, send the next chunk.
if (self.bufferOffset != self.bufferLimit) {
NSInteger bytesWritten;
bytesWritten = [self.networkStream write:&self.buffer[self.bufferOffset] maxLength:self.bufferLimit - self.bufferOffset];
assert(bytesWritten != 0);
if (bytesWritten == -1) {
[self stopSendWithStatus:@"Network write error"];
} else {
self.bufferOffset += bytesWritten;
}
}
NSLog (@"%lu",self.bufferOffset);
这是一些输出:
2013-02-24 15:54:39.674 prog[298:303] 32768
2013-02-24 15:54:39.728 prog[298:303] 4820
2013-02-24 15:54:39.791 prog[298:303] 10820
2013-02-24 15:54:39.853 prog[298:303] 16580
2013-02-24 15:54:39.911 prog[298:303] 23780
2013-02-24 15:54:39.965 prog[298:303] 28100
2013-02-24 15:54:40.024 prog[298:303] 32768
2013-02-24 15:54:40.080 prog[298:303] 6852
2013-02-24 15:54:40.139 prog[298:303] 14052
2013-02-24 15:54:40.197 prog[298:303] 18372