Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does this mean what I think it means?

Status
Not open for further replies.

AdaHacker

Programmer
Sep 6, 2001
392
US
Hi everybody!
I need to translate a CRC-16 implementation in C into VB, and I'm having some trouble, mainly because my C isn't so hot.

First question:
Does this line mean what I think it does?
Code:
crc = ((crc ^ 0x4002) << 1) + 1;
Here's what I'm guessing it's equivalent to (in pseudo-code):
Code:
temp = crc XOR 0x4002;
temp = temp SHIFTLEFT 1;
crc = temp + 1;
Is that about right?

Second question:
What does the &quot;register&quot; keyword mean? The code I'm working with has a parameter and several varisables that are declared like this:
Code:
register unsigned crc;
register char c;
I tried removing the &quot;register&quot; from the declarations, just to see what it would do, and the calculation still worked. So what does the &quot;register&quot; mean?

Thanks in advance!
 
AdaHacker,

First Question: Yes, your pseudo-code correctly interprets the code.

Second Question: Register is a request to the compiler to allocate a local variable in the general purpose registers instead of on the stack, for increased performance. The use of cache memory and optimizing compilers have mostly made this key word irrelevent. It's presence or absence should not affect the correctness of the code, as you have already noted.

Brudnakm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top