bjrnove wrote:
One thing. Why do you return a char* if 0 is going to be ok? If I was
going to write such a function I would make a couple of changes. First
of all I would make the definition something like this:
int make_hash(char* in, size_t insize, char* out, size_t outsize);
This makes it possible to make a hash of something that's not \0
terminated. I would also alow me to return different errorcodes for
different errors. The outsize I would use as a maximum size for the
output. This make the caller responsible for allocating the memory and
I usaly find that more safe for memory leaks. Another thing about the
outsize is that with a hash youknow the size. It will always be the
same and therefor you are able to hash define the size.
Keep things simple. The point of a hash is to return an integer of
some size, nothing more (apart from the distribution). So there is
no need to allocate any memory anywhere. The most common use of a
hash is on nul terminated strings, so supplying a length parameter
means prescanning the string with strlen, and will be a significant
unneeded slowdown. What errors (apart from hardware) can occur? A
properly designed hash will have no integer overflows, etc. so an
error return is pointless. Even if I am wrong, some hash
algorithms cannot return zero (such as a CRC with proper
initialization) so a zero error return is perfectly feasible.
You can find some hash functions and tests on them in:
<http://cbfalconer.home.att/download/hshftst.zip>
which you can easily modify to include further functions. It uses
the instrumentation in hashlib to measure the efficacy of the hash
on the data.
DLLs don't enter into it. They are meaningless to the C language,
and thus OT here.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson