[DGD] Re: #Including code.

Troels Therkelsen troels at 2-10.org
Sat Jan 10 18:18:14 CET 2004


> On Sat, Jan 10, 2004 at 01:17:39PM +0100, Troels Therkelsen wrote:
> [...]
> > This is all fine and well, but it can have an unexpected
> > (indeed even undesirable) effect.  Take this example
> > (assume that print() is just a function that outputs to
> > the console screen):
> > 
> > a.c:
> > ----
> >   void test_proto();
> > 
> >   void test_proto() {
> >     print("*** A ***");
> >   }
> > 
> >   void do_stuff1() {
> >     test_proto();
> >   }
> > 
> > b.c:
> > ----
> >   inherit "a"
> > 
> >   void test_proto() {
> >     print("*** B ***");
> >   }
> > 
> >   void do_stuff2() {
> >     test_proto();
> >   }
> > 
> > b->do_stuff1() ==> "*** B ***"
> > b->do_stuff2() ==> "*** B ***"
> 
> As far as I can see this is a feature, not a bug.  If you wanted
> do_stuff1() to insist on using a.c's test_proto(), then make it use a
> different function and make it a private or nomask function so nobody
> inheriting it can redefine it.  All you did now was provide a default
> implementation for test_proto() which you override in b.c.
> 
> Did I miss something?

Nopes, you are absolutely right.  My point just being that I've had to
debug way too much LPC code written by other people that bugged out due
to people using function prototyping ala C (ie., #include a header file
which has a prototype for every function in the file).  LPC function
prototyping should only be done if you want exactly the behaviour above.

IOW, if you *don't* prototype test_proto() in a.c then do_stuff1() will
indeed print "*** A ***".  Many people who use function prototypes per
default (simply because that's how the defacto standard is in C and they
apply it linearily to LPC aswell) are not aware of this.

Regards,

Troels Therkelsen
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list