Re: bitwise operator on a struct
Groovy hepcat Mark A. Odell was jivin' on 20 Jun 2003 16:44:24 GMT in
Re: bitwise operator on a struct's a cool scene! Dig it!
>firstname.lastname@example.org (asm_fool) wrote in
>> I have two questions:
>> 1) We cannot use the bitwise operator on a struct. I would like to
>> know weather following way of using the bitwise operator on a struct
>> is correct?
>> #include <stdlib.h>
>> #include <string.h>
>> struct node
>> int y;
>> struct node *p;
>> int *k;
>> p->y =1;
>You should malloc() memory for p first.
>> printf("%d %d\n",*p,p->y);
>*p is meaningless. Try %p for pointers and cast them.
I don't think he wants to print the pointer. I could be wrong,
>> k = (int*)p;
>> *k = (*k << 1);
>This doubles the pointer, now you are really pointing at garbage.
No, it doesn't. It shifts left whatever the pointer points at. * has
higher precedence than <<, so this is shifting *k, not k.
>> memcpy(p,k,sizeof *p);
>A function call to get the pointer 2 x p back into p? Time to read K&R2
>and do the examples.
No, a function call to get what the pointer k points at into the
memory the pointer p points at. Of course, both k and p point at the
same place, so this is utterly pointless.
>> 2) Is using bitwise operator for integral type is fast in execution?
>> What does standard say?
>What is your personal experience?
>I have never doubled pointers to unallocated memory.
I doubt that he has ever done that either.
>> 3) Can we use the bitwise operator for linked list for moving a list
>> for faster performance?
>You can but how an I doubt a modern compiler actually uses a divide or
>multiply, it will use a shift for powers of two divs and muls.
What does that have to do with "moving a list" (whatever that
Dig the even newer still, yet more improved, sig!
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
|All times are GMT. The time now is 02:27 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.