Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to cast an int64_to to a const void ptr

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading