casting - why does gcc(default version on openSUSE 11.3) give an error on the statement int *p=malloc(sizeof(int));? -


malloc returns void pointer.so why not working me without typecasting return value? error pretty clear said gcc not allowing conversion void* int*.

in c, don't have cast. in fact it's bad idea cast there since can cause subtle errors.

however, casting is required in c++ first guess, you're somehow invoking c++ compiler. perhaps source files *.cpp or *.c both of may auto-magigically treated c++ rather c.

see here more detail:

c++ source files conventionally use 1 of suffixes ‘.c’, ‘.cc’, ‘.cpp’, ‘.cpp’, ‘.c++’, ‘.cp’, or ‘.cxx’; c++ header files use ‘.hh’, ‘.hpp’, ‘.h’, or (for shared template code) ‘.tcc’; , preprocessed c++ files use suffix ‘.ii’. gcc recognizes files these names , compiles them c++ programs if call compiler same way compiling c programs (usually name gcc).

the fact knows you're trying convert void* int* means have valid malloc prototype in place can't see being other imposition of c++ rules.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -