LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2011, 01:18 AM   #1
gfmtech05
LQ Newbie
 
Registered: Apr 2011
Location: United States
Distribution: Debian
Posts: 24

Rep: Reputation: 7
MD5 Algorithm Implementation


I have a copy of the MD5 algorithm and I'm taking a look at the source. It's pretty interesting but there are a few things that I'm curious about and I was wondering if anyone a bit more intuitive than I could help me out.

The function declarations in the MD5 files are a bit unfamiliar to me. There is a macro used called PROTO_LIST, which I'm still not sure as to what this thing is doing exactly, but it's littered everywhere throughout the source. The macros is defined as follows:

Code:
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif
(NOTE: PROTOTYPES macro is apparently dependent upon the target compiler supporting function argument prototyping according to the header)

For example, md5.h prototypes three functions that utilise this macro in that particular statement. For example, one prototype looks like this:

Code:
void FuncName PROTO_LIST ((MD5_CTX *))
The signature here isn't too unfamiliar to me with the exception of the position of the PROTO_LIST macro. So here is a function with an unnamed argument of type MD5_CTX*. As expected, at the function's definition in the accompanying source file, the argument is named but this is where things get really confusing for me as I've never seen this type of definition before:

Code:
void FuncName (context)
MD5_CTX *context;
{
   // Code omitted for brevity...
}
To me, this resembles an initializer list found in C++ with constructors but I certainly don't think that is the case here. So my questions about this are (1) how is this legal code in C and (2) what functionality has the PROTO_LIST macro provided for the function?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-27-2011, 03:54 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by gfmtech05 View Post
As expected, at the function's definition in the accompanying source file, the argument is named but this is where things get really confusing for me as I've never seen this type of definition before
This is an old style C function, where the argument types could (optionally) be specified just before the body of the function. This is now obsolete (having been replaced by prototypes where the arguments are defined inside the brackets), however you will find it in legacy code.

Quote:
There is a macro used called PROTO_LIST, which I'm still not sure as to what this thing is doing exactly, but it's littered everywhere throughout the source.
The problem with old style C functions is that it is hard to declare an interface, since newer compilers of C will require a prototype and older ones won't understand it. The PROTO_LIST macro is merely a way of optionally providing the argument list for the newer compilers.

So everywhere you see PROTO_LIST, just ignore it; the contents of the brackets are the argument list of the function.
 
3 members found this post helpful.
Old 04-28-2011, 07:21 AM   #3
gfmtech05
LQ Newbie
 
Registered: Apr 2011
Location: United States
Distribution: Debian
Posts: 24

Original Poster
Rep: Reputation: 7
Okay so if I understand what you said correctly then the source is implementing a legacy method of prototyping that is now deprecated? So this method of prototyping is also subjective to the target compiler as well?

Thanks for the clarification on that matter. I'd honestly never seen function signatures written that way before. That macro definition really threw me off there.
 
Old 04-28-2011, 08:06 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by gfmtech05 View Post
Okay so if I understand what you said correctly then the source is implementing a legacy method of prototyping that is now deprecated? So this method of prototyping is also subjective to the target compiler as well?
Yes. Although not strictly a legacy 'prototype'; there was no method at all for prototyping in the earlier versions of C (since the declarator had no arguments). The declaration of the argument types in the function definition were only for compiling the body of the function.

The C99 standard uses the term 'an obsolescent feature' rather than the C++ term 'deprecated', though the meaning is similar; the feature might be taken out of future revisions of the standard.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
implementation of RSA algorithm in C / C++ rupa sarda Programming 1 08-02-2010 11:12 AM
need help unpacking hmac-md5 hash into md5 hash lynx5 Programming 3 02-02-2008 04:06 PM
difference between md5 shadow and md5 elsewhere? whysyn Linux - Security 5 12-11-2007 10:11 AM
token bucket algorithm vs Leaky bucket algorithm xeon123 Linux - Networking 2 03-26-2007 04:57 AM
hash bye md5 algorithm vishalbutte Programming 5 02-18-2006 10:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration