문제

Ok, this compiles fine in GCC under Linux.

char * _v3_get_msg_string(void *offset, uint16_t *len) {/*{{{*/
    char *s;
    memcpy(len, offset, 2);
    *len = ntohs(*len);
    s = malloc(*len+1);
    memset(s, 0, *len+1);
    memcpy(s, offset+2, *len);
    s[*len] = '\0';
    *len+=2;
    return s;
}/*}}}*/

However, I'm having a problem porting it to Windows, due to the line...

memcpy(s, offset+2, *len);

Being a void pointer, VC++ doesn't want to offset the pointer. The usual caveat that CPP doesn't allow pointer offsets SHOULD be moot, as the whole project is being built under extern "C".

Now, this is only 1 function in many, and finding the answer to this will allow them all to be fixed. I would really prefer not having to rewrite the library project from the ground up, and I don't want to build under MinGW. There has to be a way to do this that I'm missing, and not finding in Google.

도움이 되었습니까?

해결책

Well, you cannot do pointer arithmetics with void*, it is ridiculous that this compiles under GCC. try memcpy(s, ((char*)offset)+2,*len);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top