Can’t compile ftpupload.c

I’m trying to compile ftpupload.c with command g++ -o program ftpupload.c, but I get the following error:

ftpupload.c: In function ‘size_t read_callback(char*, size_t, size_t, void*)’:
ftpupload.c:57:50: error: invalid conversion from ‘void*’ to ‘FILE* {aka _IO_FILE*}’ [-fpermissive]
   size_t retcode = fread(ptr, size, nmemb, stream);
In file included from ftpupload.c:22:0:
/usr/include/stdio.h:646:15: note:   initializing argument 4 of ‘size_t fread(void*, size_t, size_t, FILE*)’
 extern size_t fread (void *__restrict __ptr, size_t __size,


This is compiling a C source file as C++. C++ is stricter when it comes to implicit conversions and does not allow an implicit conversion from a void* to any other pointer (source):

Pointer to object of any type can be implicitly converted to pointer to void (optionally cv-qualified); the pointer value is unchanged. The reverse conversion, which requires static_cast or explicit cast, yields the original pointer value: [..]

To resolve this, either use a C compiler or add a cast:

size_t retcode = fread(ptr, size, nmemb, static_cast<FILE*>(stream));

It is not recommended, but if this line needs to be bilingual C and C++, you could use a C-style cast:

size_t retcode = fread(ptr, size, nmemb, (FILE*) stream);

On a side note: ftpupload.c does not contain a standalone program and will not fully compile even with the cast. The best solution depends on why you’d like to compile this file in the first place.