[H-GEN] C code.
In memory of Mighty
s335810 at student.uq.edu.au
Mon Oct 27 16:20:43 EST 1997
Isn't this fun, evaluating the evaluations!
On Tue, 28 Oct 1997, Anthony Towns wrote:
> Personally, I'd change HASH_REPORT() to something like:
>
> #ifdef HASH_DEBUG
> #define HASH_REPORT(str) fprintf(stderr, "DEBUG: %s\n", str )
> #else
> #define HASH_REPORT(str) (void)0
> #endif
I quite like this layout <thinking> there's no way to indent
#defines is there? Personally I don't use complex macros because they are
difficult to work out and get correct, especially for the novice (read
average actual) C programmer.
> 1) Using %s is a small gain: it lets you use non-literal strings, and
> it also means you don't need "DEBUG: " stored n times in the
> program/memory, only once. It's only loss is that it won't give you a
> compile time error for HASH_REPORT(1), although adding the -Wall -W
> arguments to gcc will give you a warning. Which is why C++ prefers
> inline functions. I'm under the impression C9X (the up and coming
> review of C) will allow inline functions, among other things like
> "for(int i=...)".
Well, actually you get "DEBUG: %s\n" plastered all through the
code instead... but not to get picky. If you're in a situation where
those bytes are important, you're an engineer and should be shot.
> Wrt your "typedef struct _IntHashTable IntHashTable;", I personally
> prefer
> typedef struct IntHashTable {
> /* definition */
> } IntHashTable;
> as my declaration. It doesn't introduce any unwieldy underscores, and
> since the namespaces are treated separately also don't cause a
> problem.
This appears to avoid giving away private type definitions in the
header file. This is a good thing, even though you really shouldn't be
using C in the first place if you're that concerned about it <ducks>
> In C, I tend not to use the StudlyCaps naming convention (or the
> MaimingConvention as I called it in one of my C assignments...) but
> rather to use all lower case, with words separated by underscores. I
> find the fits in with the standard library much more nicely.
I think you (and probably he) have missed the point that what
you're looking at is an Ada program... written in C. <smile>
> There no need to cast malloc's return value. It's no big deal, but
> without the case it will give you an error if you neglect to include
> stdlib.h, and (void*)'s are _guaranteed_ to be automatically typecast
> correctly for you.
<untested> Doesn't it give exactly the same warning? ... that is
that it is assuming a definition the function? Surely casting won't cause
it to assume a return of the cast type...? Or am I just thinking in the
small world of gcc, where things actually work?
> The description in your header file "stored as a mod/bucket" didn't
> make sense to me. You latter state that "the array is hashed as key %
> size". This might have been nicer in the description at the top to
> clarify the modules description for the clueless.
A mod/bucket is saying that the hashing is done by modulus, and is
stored in buckets (small linked lists), as opposed to some other collision
recovery algorithm. I think that's what's implemented, but for no
particular reason I didn't sleep last night. I'm not going to go looking
again.
> I notice you use calloc to allocate the hash table itself, then go to
> the effort to intialize it by hand immediately after. This seems
> wasteful. Hmmm... Since you rely on the NULL's being there switching
> to malloc would be sensible, IMO.
I noticed this one also. The only part which is not automatically
set right is NULL. I would have just commented that the others were done
myself. Let calloc do it's good work, then make corrections... Or maybe
I'd just do it the other way. Depends on the color of the clinker I'm
eating I guess.
Oh, and I forgot to mention that the code is of a higher quality
than I would have bothered putting out <smile>
In memory of Mighty <memory at techie.com>
/// /// /// /// /// /// /// // // //
/// /// /// /// /// // // //
/// /// /// /// // // //
/// /// /// /// /// ///
/// ///////// ///////// /// /// // // //
I will not play it. This game of loneliness
Web page at http://student.uq.edu.au/~s335810
----------------------- HUMBUG General List --------------------------------
echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe
More information about the General
mailing list