Re: C++ compiler warnings with dlsym()

From: Anil Mahajan (amahajan@PROXICOM.COM)
Date: 03/02/99


On Sat, 27 Feb 1999 11:30:18 -0500, Daniel Burke <addictmud@home.com> wrote:

>comm.c: In function int main(int, char **)':
>comm.c:249: warning: ANSI C++ forbids cast to non-reference type used as
>lvalue
>
>      void (*gen)(void);
>
>      if (!((void*)gen = dlsym(libboot, "boot_world__Fv"))) {
>
>Does anyone know if a better way I can type-cast that or define "gen" so it
>doesn't product a warning?
>
  Hmm... my C++ is a bit rusty, but I've do shared objects on my MUD, too.
but it's still in C.  Does c++ properly handle void pointers?  i guess it'd
have to.
  The error itself is probably caused because you are casting the lvalue (gen)
instead of the rvalue (the dlsym() call)... but, there is a deeper issue here.

  I think your if stmt needs to be reworked.  dlsym() will return a NULL if
the function is not found. I don't think the man page specifies what it will
return on an error.
  It does however state that you can use the output of the dlerror()
function to test if the previously done dlsym() command was problematic.
There are examples of this in the Linux man page, and I use this technique
without any compiler warnings on my MUD.
  Here's an example from my code:

        func = dlsym(SpecModule->handle, SpecProcList[i].func);
        if ((error = (char *) dlerror())) {

  error is defined as 'char *error'
  func is defined as 'SPECIAL(*func)'


try that out, and see if the warnings go away.

- Anil


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST