I m 书写一个图书馆,使用一个固定地点C-array的Byte,定义是Zlib.h。 我发现,这部法典用电击 me。 完整的法典就是这样:
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!