C function prototype declaration

Today I saw a prototype of a form function (for completeness, a few initial lines were added)

typedef unsigned char md5_byte_t; /* 8-bit byte */ typedef unsigned int md5_word_t; /* 32-bit word */ /* Define the state of the MD5 Algorithm. */ typedef struct md5_state_s { md5_word_t count[2]; /* message length in bits, lsw first */ md5_word_t abcd[4]; /* digest buffer */ md5_byte_t buf[64]; /* accumulate block */ } md5_state_t; void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); 

This was done in the form of an implementation of md5 L. Peter Deutsch. From what I know, writing 16 in the prototype makes no sense. So why is it included here

This is just an indication to the programmer that any pointer or array that you pass to the function will only take the first 16 bytes into account. What does it really mean here. here is a link to the implementation hosted on github

+6
source share
1 answer

In practice, it will break up into

void md5_finish(md5_state_t *pms, md5_byte_t *digest);

16 may be a hint for the size that will be used for the digest for the user, but the function will technically take any size in the parameter, unless the code in the function checks the specific size.

+7
source

Source: https://habr.com/ru/post/920615/


All Articles