#if AV_GCC_VERSION_AT_LEAST(4,3)
#define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
#else
#define av_alloc_size(...)
#endif
/**
* Allocate a memory block for an array with av_mallocz().
*
* The allocated memory will have size `size * nmemb` bytes.
*
* @param nmemb Number of elements
* @param size Size of the single element
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
*
* @see av_mallocz()
* @see av_malloc_array()
*/
av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb,
size_t size)
{
if (!size || nmemb >= INT_MAX/size)
return NULL;
return av_mallocz(nmemb * size);
}
我是一個C浪底。我在閱讀開源時看到了這個功能。但是它有什麼樣的功能呢?我從來沒有見過這種功能。 av_alloc_size(1, 2)
和*av_mallocz_array
有什麼關係?嵌套的C語言函數
'av_alloc_size'是*預處理宏*。 [一本好的初學者書](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list)應該談論它們。如果你是初學者,那麼你正在看的代碼可能會爲你提高一點。在像例如項目中的代碼對於初學者,ffmpeg是* not *。 –
謝謝你的解釋 – Saqrag