I do not use 'object *' at all in my code. If I did, all would
work fine, but then the compiler would not warn me that I am
passing things where they should not be. Currently I am
having to cast everything because they are NOT prototyped using
'listobject *'. :( Looks like different programmig styles have
clashed. Oh well..
>It's true that now there's a cast inside listgetsize(), but that's one
>cast per function definition instead of one cast per function call.
>Also note that getlistsize() tests its argument for list-ness.
>Strictly spoken this should be redundant, but many people (including
>me!) sometimes write sloppy code that doesn't always check the types
>of objects passing through a function. The function err_badcall()
>(used in such occasions) currently raises an exception, but can easily
>be changed to call abort(), which pin-points the cause of the error
>much better than a segmentation violation caused by accessing a
>non-list as if it were a list...
All functions should test for the correct type being passed in.
This is a given. I would feel the code was VERY broken if it did NOT
check for this. By always using the correct type, 'listobject *' or
'tupleobject *', instead of the generic 'object *', it also makes
programs easier to tell what is going on (at least I think so..), but then
I have to deal with ANSI compilers that complain on every function call
that I am passing the wrong type. So I either cast EVERYTHING (what a
waste!) or I change the xxobject.h files (as I have done) to accept the
correct type. This will also force the compiler to give a warning/error
if I am passing in a non-typed object, i.e. 'object *', instead of the
correct one. Makes you look over your code a little more.
>Finally note that at least it's reasonably consistent: newlistobject()
>returns an "object*", and getlistsize() takes one...
I think this is wrong. newlistobject() should return a 'listobject *'
instead of a 'object *'. It may be consistent, but I think it is wrong.
If I am the only one in the world that does feel this way, I will
shut my mouth and keep quiet.