I've worked on this function, but There's still a problem.
Benjamin_cail_scott 25 November 2004 07:49:33
This function is suppose to be supplied with a bunch of bytes for A, and one byte B. It then AND's all of the bytes in A with the byte in B. However, in compiling all I get is the following errors: I placed them after the line that causes them. There must be a problem with my use of the binary '&'. It can be used on bytes right?
void *AND(void *A, void *B) ||| [Warning] In function `AND':
------------------------ Yahoo! Groups Sponsor --------------------~--> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. Now with Pop-Up Blocker. Get it for free! http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM --------------------------------------------------------------------~->
This function is suppose to be supplied with a bunch of> bytes for A, and one byte B. It then AND's all of the> bytes in A with the byte in B. However, in compiling> all I get is the following errors: I placed them after> the line that causes them. There must be a problem> with my use of the binary '&'. It can be used on bytes> right?
Yes, but it can't be used on pointers, which is what your code is attempting to do.
void *AND(void *A, void *B) ||| [Warning] In function `AND':
This is a really untidy interface (especially when you have a magic constant embedded).
{> char i;
Although it's unlikely to make a difference to most compilers, an int would be better than a char.
Firstly, temp is a pointer to a char sequence, therefore temp[i] is a char. You can't assign a (char *) to a char.
Secondly, both place and B are pointers to bytes, not bytes, so you can't apply the bitwise and operator.
Thirdly, you can't dereference place and B to obtain respective byte values since they are both pointers to void, not pointers to character.
place++;
This is also a constraint violation as you cannot apply an increment operator to a pointer to an incomplete type (i.e. void *). [Many compilers allow it, but if you set up your compiler options correctly, you SHOULD have at least received a warning about this too.]
};> return (void *) temp;> };
Why are you allocating this dynamically? This could fail, and you place the burden of deallocation back on the caller.
I would do something like...
/* Bitwise AND n bytes from A with mask byte M, // putting the result into R. */ void AND( const unsigned char *A, size_t n, unsigned char M, unsigned char *R ) { size_t i; for (i = 0; i < N; i++) R[i] = A[i] & M; }
-- Peter
------------------------ Yahoo! Groups Sponsor --------------------~--> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. Now with Pop-Up Blocker. Get it for free! http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM --------------------------------------------------------------------~->
If you would like to report an abuse of our service, such as a spam message, please . Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .