What is "Friend entries"?
I've worked on this function, but There's still a problem.
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > C/C++ Programming > I've worked on this function, but There's still a problem. 25 November 2004 09:10:44

  Top users: 
  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

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':

{
char i;
char *temp;
void *place;
temp = (char *) malloc(16);
place = A;
for(i = 0;i < 16;i++)
{
temp[i] = (char *) (place & B); ||| invalid operands to binary &
place++;
};
return (void *) temp;
};






-------------------­----- 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.yah­oo.com/L5YrjA/eSIIAA­/yQLSAA/EbFolB/TM
-------------------­--------------------­--------------------­---------~->

Add comment
Peternilsson42 25 November 2004 09:10:44 permanent link ]
 

"benjamin_cail_scot­t" <benjamin_cail_scot­t@y...> wrote:>
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.
char *temp;> void *place;> temp = (char *) malloc(16);

You should check that this succeeds. The cast to (char *) is utterly
redundant in C, as is your cast of the return value.
place = A;> for(i = 0;i < 16;i++)> {> temp[i] = (char *) (place & B); ||| invalid operands to binary &

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.yah­oo.com/L5YrjA/eSIIAA­/yQLSAA/EbFolB/TM
-------------------­--------------------­--------------------­---------~->

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > C/C++ Programming > I've worked on this function, but There's still a problem. 25 November 2004 09:10:44

see also:
[Beginners Corner] - how to connect…
[JBoss Portal] - Re: portal 2.0…
[JBoss jBPM] - Re: horrible experience…
pass tests:
see also:
Is there somebody who plays on...
Have you ever caught in such cases…
privetic

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .