Structure pointer question

T. William Wells bill at proxftl.UUCP
Mon Jul 11 18:30:06 AEST 1988


In article <399 at teletron.UUCP>, andrew at teletron.UUCP (Andrew Scott) writes:
> In article <424 at proxftl.UUCP>, bill at proxftl.UUCP (T. William Wells) writes:
> > The correct solution is to have your library deal with void *.
> > If a raw void * bothers you, use typedef void *MESSAGE; and then
> > type everything as MESSAGE.
>
> Indeed, I have been informed that this is the only truly portable way of doing
> things.  HOWEVER, I do not have a compiler that supports "void *" at the
> moment, and I cannot stand seeing lint all hot and bothered about casts to
> and from "char *".  :-)
>
> Terrible reasons, I know, but it does look "cleaner" than using void * (to me,
> at least) and I think it *would* be portable if all pointers to structures
> had the same format.

As I have come to see, while it is the case that structure
pointers are somewhat equivalent, in the same way that constant
zero and null pointers are somewhat equivalent, they do not have
to have the same format. As I said, this is likely to work but
not guaranteed, since while most implementations have all
structure pointers with the same format, there is nothing that
requires this.

Were I you, I'd first try to get a new compiler, and failing
that, I'd live with the messages from lint.  If I really
couldn't hack that, I'd create some programming to filter out
the irrelevant complaints from lint.

Also, to save yourself some grief, should you decide to go the
char * route, write them as VOID * (or even void * if you are
not afraid of getting a compiler that will barf on that) and use
a typedef. This will save you headaches when you switch
compilers. It might also make the programming mentioned in the
previous paragraphs easier.



More information about the Comp.lang.c mailing list