Page 1 of 1

DJGPP Compiler Warning...

Posted: Sat Mar 08, 2003 5:10 pm
by chrisa128
warning: passing arg 1 of 'memcpy' discards qualifiers from pointer target type
Can anyone give me any ideas on fixing this?

Re:DJGPP Compiler Warning...

Posted: Sat Mar 08, 2003 6:08 pm
by Tim
You've probably done something like this:

Code: Select all

const char *str = "Hello ";
mempcy(str, "World", 6);
memcpy() is prototyped as:

Code: Select all

void *memcpy(void *dest, const void *src, size_t bytes);
...so by passing const char* as the first parameter, you're discarding the const qualifier.

Re:DJGPP Compiler Warning...

Posted: Sun Mar 09, 2003 10:40 am
by chrisa128
My memcpy is as follows...

Code: Select all

void *memcpy(void *dst_ptr, const void *src_ptr, unsigned count)
{
   void *ret_val = dst_ptr;
   const char *src = (const char *)src_ptr;
   char *dst = (char *)dst_ptr;
   for(; count != 0; count--)
      *dst++ = *src++;
   return ret_val;
}
The code I am calling it from is

Code: Select all

static volatile virtual_stream virtual_sessions[10];

FILE *retval = kmalloc(sizeof(FILE));

memcpy(&virtual_sessions[totalvirt].substream, retval, sizeof(FILE));

Code: Select all

typedef struct
{
   char *truepath;
   int objid;
   FILE substream;
} virtual_stream;

typedef struct
{
   int type, id;
   int location;
   int mode;
} FILE;

Re:DJGPP Compiler Warning...

Posted: Sun Mar 09, 2003 5:45 pm
by Tim
OK, discarding 'volatile' isn't as bad as discarding 'const'. Cast the pointer, removing volatile, and you should be fine. It's generally not a good idea to shut the compiler up by inserting casts, but as long as you understand why, it's OK.