0

I'm writing a library that uses a statically-allocated C-array of type Byte, defined in zlib.h. I'm finding that the code crashes on a call to memset. The complete code looks like this:

Byte compressedDataBuffer[kLabelBufSiz]; 
memset (compressedDataBuffer, 0, (kLabelBufSiz * sizeof(Byte)));

I tried pre-computing the value of kLabelBufSiz * sizeof(Byte) and using the numeric value for the memset, but it made no difference. This is a single-threaded program and there is no code between the two calls, so I know that the memory and pointer are not changing. I confirmed that sizeof(Byte) is 1. I tried changing the array type to char, and that stopped the crash, so it seems that the Byte type may be playing a role here.

I wrote a smaller program that calls this library function, and that one does not crash. The non-crashing program is pure C++, whereas the crashing one is Objective-C++. I'm building them both on Mac OSX 10.6.7, with gcc-4.2 and XCode. Is there something about ObjC++ that could cause problems here? I've never had problems with C++ libraries called from ObjC++ before, but that doesn't mean they don't exist. Any help is greatly appreciated!

4

1 回答 1

0

Byte 是一个包装类。使用字符而不是字节。除非你必须使用 Byte,否则不要使用 memset

于 2011-07-21T19:28:32.027 回答