I accidentally assign
int * c = malloc(sizeof(int));
$gcc test.C -o test
test.C:8:18: error: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive]
int * c = malloc( sizeof(int) );
Linux ee 4.8.0-36-generic #36~16.04.1-Ubuntu SMP i686 i686 i686 GNU/Linux
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
gedit - Version 3.18.3
.C (capital letter) extension as C++ file. You need to change extension of your file to
.c (small letter). Also, you rightly mentioned and referenced that C++ requires a cast in case of malloc where as in c there is an implicit conversion from any object pointer type to void *.
See below explanation about file extensions (
.c) from GCC documentation. Please refer below GCC link for detail explanation for various file extensions.
C++ source code which must be preprocessed. Note that in .cxx, the last two letters must both be literally x. Likewise, .C refers to a literal capital C.
C source code which must be preprocessed.
Additionally, you can give the flag
-x c to force GCC to treat the file as C, not C++.