Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

struct iovec is defined in <uio.h> by the following way:

/* Structure for scatter/gather I/O.  */
struct iovec
  {
    void *iov_base; /* Pointer to data.  */
    size_t iov_len; /* Length of data.  */
  };

Now I do ugly casting from const void* to void*:

int send_frame_once( int fd, const struct iovec* iov, size_t iovlen );


int send_frame( int fd, const void* buffer, size_t len )
{
    struct iovec iov;
    iov.iov_base = (void*)buffer;       /* const iov cast */
    iov.iov_len  = len;
    return send_frame_once( fd, &iov, 1 );
}

Is that necessary kludge? Or should I remove const keyword from declaration of send_frame function. Like this:

int send_frame( int fd, void* buffer, size_t len )
share|improve this question
up vote 5 down vote accepted

I think you should keep it. const is not only meant for the compiler, but also for anybody reading your code. Even with the void* cast, you're still saying to readers "Trust me, I'm not touching your buffer!" and this is a valuable information that should not be discarded.

share|improve this answer
1  
assuming send_frame does not alter the content of buffer in any way. – Loki Astari Feb 29 '12 at 14:34
    
Indeed, this is what I am assuming here. – Quentin Pradet Feb 29 '12 at 14:35
1  
Yep, buffer is not modified. – User1 Mar 1 '12 at 8:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.