Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to define return string in DLL?

Reply
Thread Tools

How to define return string in DLL?

 
 
huey_jiang@yahoo.com
Guest
Posts: n/a
 
      03-30-2005
Hi All,

I need to make DLL for my new hash function in C. In myhashdll.c file,
I have a function as:

char *make_hash(char *in, char *out)
{
......
......
return (out);
}

So, this function is supposed to return a hashed string in the *out
argument. What I don't know is how to define its header file. Say, in
myhashdll.h file, I need to define 2 values that tell my main() whether
this make_hash() call works good or not. If do defines as:

#define HASH_OK 0
#define HASH_ERR 44

I think these 2 defines should not work right, because my return will
be a hashed sring, instead of 2 numbers. Can anybody help me to figure
out how to do these 2 defines? I mean, to make the defines that can
return my hashed string.

Sorry for the complexity of the question. Thanks in advance!

Huey

 
Reply With Quote
 
 
 
 
bjrnove
Guest
Posts: n/a
 
      03-30-2005
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.

So basicly, theres seems to be no good reason for you to return a
char*, and second of all, why return NULL on success?

--
bjrnove

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      03-30-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
About typedef -- define the function pointer or define function model? robin liu C Programming 3 04-21-2006 03:26 PM
#define _ and #define __ Brian Takita Ruby 0 01-23-2006 04:34 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
How to define a define that defines some defines ? theotyflos C Programming 3 02-19-2004 05:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57