Subject: -Wcast-qual and assignement to strucutres
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 02/13/2006 01:33:53
Hi,
I've a problem with -Wcast-qual: I have the following function:

static int
xs_talkv(struct xenbus_transaction *t,
                      enum xsd_sockmsg_type type,
                      const struct iovec *iovec,
                      unsigned int num_vecs,
                      unsigned int *len,
                      char **retbuf);
[...]
static int 
xs_single(struct xenbus_transaction *t,
                       enum xsd_sockmsg_type type,
                       const char *string,
                       unsigned int *len,
                       char **ret)
{
        struct iovec iovec;

        iovec.iov_base = string;
        iovec.iov_len = strlen(string) + 1;
        return xs_talkv(t, type, &iovec, 1, len, ret);
}

The compiler complains on iovec.iov_base = string:
/local/pop1/bouyer/current/src/sys/arch/xen/xenbus/xenbus_xs.c: In function `xs_single':
/local/pop1/bouyer/current/src/sys/arch/xen/xenbus/xenbus_xs.c:239: warning: assignment discards qualifiers from pointer target type

but I know the iovec pointer passed to xs_talkv is read-only. But I don't know
how to express this in this function. If I change struct iovec iovec to
const, then the compiler complains that I'm writing to a read-only member.
Any idea on how to fix this ? Dropping const from xs_single's prototype isn't
an option (and string is really const, it won't be writtent to).

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--