473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What do these casts accomplish?

I am looking at the C++ MD5 implementation found on this site:
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html. I'm a bit unsure as to
the necessity and/or effect of the various casts appearing in the
following:

typedef unsigned int uint4;
uint4 count[2]; // number of *bits*, mod 2^64

void MD5::update (uint1 *input, uint4 input_length) {

uint4 input_index, buffer_index;
uint4 buffer_space; // how much space is left in buffer
/...

// Compute number of bytes mod 64
buffer_index = (unsigned int)((count[0]>>3) & 0x3F);

// Update number of bits
if ((count[0]+=((uint4)input_length<<3)) < ((uint4)input_length<<3))
count[1]++;

count[1] += ((uint4)input_length >> 29);

//etc...
}

Firstly, I'm wondering if there could be any functional advantage to not
using the typedef in the first cast.

buffer_index = (unsigned int)((count[0]>>3) & 0x3F);

My guess is the programmer simply overlooked it when converting from using
builtin names to using the typedef.

More significantly, I'm unsure of what those typedefs might accomplish, or
the consequences -if any- of omitting them. Does anybody see functional
value in having them in the code? What might that be?
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Feb 20 '06 #1
2 1370
Steven T. Hatton a écrit :
Does anybody see functional
value in having them in the code?


I don't see any.
Feb 20 '06 #2
Steven T. Hatton wrote:
I am looking at the C++ MD5 implementation found on this site:
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html. I'm a bit unsure as to
the necessity and/or effect of the various casts appearing in the
following:

typedef unsigned int uint4;
uint4 count[2]; // number of *bits*, mod 2^64

void MD5::update (uint1 *input, uint4 input_length) {

uint4 input_index, buffer_index;
uint4 buffer_space; // how much space is left in buffer
/...

// Compute number of bytes mod 64
buffer_index = (unsigned int)((count[0]>>3) & 0x3F);
Pointless as far as I can see, since both are unsigned ints.


Firstly, I'm wondering if there could be any functional advantage to not
using the typedef in the first cast.

buffer_index = (unsigned int)((count[0]>>3) & 0x3F);

My guess is the programmer simply overlooked it when converting from using
builtin names to using the typedef.
More significantly, I'm unsure of what those typedefs might accomplish, or
the consequences -if any- of omitting them. Does anybody see functional
value in having them in the code? What might that be?


I think the reason people do it to 'future proof' code. He is saying
that 'int' is 4 bytes. This is not so on all processors. The Cray X-MP has

sizeof(short)=8;
sizeof(int)=8
sizeof(long)=8.

I've always felt 'short', int and long were silly names, and something
like int8, int16, int32, int64 would have been more logical from the
beginning. But hay, that breaks too, as I have used a processor which
had 24 bits!! The most (or it might have been the least) significant
byte was in the middle, so it was never big or little Endian.

--
Dave K

Minefield Consultant and Solitaire Expert (MCSE).

Please note my email address changes periodically to avoid spam.
It is always of the form: month-year@domain. Hitting reply will work
for a couple of months only. Later set it manually.
Feb 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
11
by: Davíð Þórisson | last post by:
hi I'm new to c# and although having read 2 tutorials I cannot find what the parenthesis in these 2 example situations mean; 1) string strKeyValue = (string)sampleConfig; 2) class myParentPage...
10
by: Ralf | last post by:
Regarding numerical types, in my view, casts fall in one of two categories: 1. Casts that change the value of an object 2. Casts that are actually redundant, but get rid of compiler/lint warnings...
16
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
132
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
28
by: charlie | last post by:
Hi, I found an article on informit.com that talks about C++ casts http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1 The strange thing is the author says the following...
81
by: jacob navia | last post by:
Hi I am still writing my tutorial book about C. Here is the section about casts. I would be interested in your opinions about this. Some people have definite views about this subject ("never...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.