Unable to cast an int64_to to a const void ptr

Advertisements

I use a C program to call a NASM program. On return, NASM passes a pointer to an array buffer back to C. I want to write that array buffer to file with fwrite. To do that, I need to cast the int64_t returned by NASM to a const void *ptr for fwrite. Here is what I have tried so far:

const void *output_ptr = rp;
const void *output_ptr = *(const void)rp;
const void *output_ptr = *(const void *ptr)rp;
*output_ptr = *(const void *ptr)rp;

but none of those work. This seems like it should be a simple question, but searching on the internet and Stack Overflow didn’t bring up any answers.

Here is the file write code:

FILE *fp = fopen (output_file.bin, "wb");
if (fp == NULL  )
    return -1;
fwrite (output_ptr, 8, length, fp);
fclose (fp);

Thanks for any help on this.

>Solution :

The form of a cast operation is (type) operand.

The type for a pointer to a const-qualified void is const void *, not const void (which is not a pointer) or const void *ptr (which has an identifier in it, ptr, that is not part of a type).

So you want (const void *) rp.

Leave a ReplyCancel reply