473,771 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_l ength<<3))
count[1]++;

count[1] += ((uint4)input_l ength >> 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 1399
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
3005
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 containing pointers into a "flattened" bit stream. Here is my code (it dosen't work - compiles fine, pack appears to work, but unpack retrieves jibberish and causes program to crash).
11
2043
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 containing pointers into a "flattened" bit stream. Here is my code (it dosen't work). I would be grateful for any feedback that helps fix this. My intention
11
1721
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 = (default_aspx) this.Page; (default_aspx is the class name for my parent Page)
10
1726
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 As an example, consider this code: unsigned int ui; ...
16
10397
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 do you mean by pointing to a void and why is it done? Aso, what happens when we typecast a pointer to another type. say for example int *i=(char *)p; under different situations? I am kind of confused..can anybody clear this confusion by clearly...
132
4653
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 community. It would seem that C99 is the most up-to-date Standard, but far more people seem to be working off the C89 Standard. Could someone please explain to me why this is so? --
28
2145
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 code will *not* compile: double d=15.95; int n= static_cast<int(d);
81
3337
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 use casts") some others (like me) are more "liberal" in this subject. I would be interested in any feedback. jacob -------------------------------------------------------------------
89
5768
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 right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.