Issue using memset in mex function

2 ビュー (過去 30 日間)
Nicolas
Nicolas 2013 年 10 月 4 日
回答済み: James Tursa 2013 年 10 月 5 日
Hi,
I'm writing my first mex function and I've been running into some problems building it. The following warning is produced:
warning: implicitly declaring library function 'memset' with type 'void *(void *, int, unsigned long)'
memset(MASK, 0, sizeof(MASK[0])*nRow*nCol);
I'm not sure why this warning is produced. Memset is used here to initialize the 2D array MASK to 0:
unsigned char *MASK;
plhs[2] = mxCreateDoubleMatrix(nRow, nCol, mxREAL);
MASK = (unsigned char *)mxGetPr(plhs[2]);
Any help would be appreciated, thank you.
  1 件のコメント
dk
dk 2013 年 10 月 5 日
編集済み: dk 2013 年 10 月 5 日
Did you #include string.h in the source code ?

サインインしてコメントする。

回答 (1 件)

James Tursa
James Tursa 2013 年 10 月 5 日
1) Include string.h as already suggested by dk.
2) You don't need to zero out the memory behind the data pointer returned by mxGetPr, since the mxCreateDoubleMatrix function automatically zero's out these values.
3) You are not zero'ing out the proper amount of memory anyway. You have a double matrix of size nRow x nCol, so that is 8 * nRow * nCol bytes, but you are only zero'ing out 1 * nRow * nCol bytes in your memset call since sizeof(MASK[0]) is sizeof(unsigned char) = 1.

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by