difference between and

前端 未结 6 664
难免孤独
难免孤独 2020-11-30 02:20

When I use malloc in a C program, I get a warning:

warning: incompatible implicit declaration of built-in function \'malloc\' [enabled by defaul         


        
6条回答
  •  甜味超标
    2020-11-30 02:49

    The header is deprecated (and quite Linux specific, on which it defines non-standard functions like mallinfo(3)). Use instead if you simply need malloc(3) and related standard functions (e.g. free, calloc, realloc ....). Notice that is defined by C89 (and later) standards, but not

    Look into /usr/include/malloc.h you'll find there some non-standard functions (e.g. malloc_stats(3), etc...) - in addition of malloc....

    And gcc don't link header files, but libraries. Read Levine's book about linkers & loaders for more.

    If you don't include any headers (and dont explicitly declare malloc yourself, which would be a bad idea), malloc is implicitly declared as returning some int value (which is wrong). I do invite you to pass at least the -Wall flag to gcc when using it.

    You might also pass -v to gcc to understand the actual programs involved: cc1 is the compiler proper (producing assembly code), as the assembler, ld the linker, and collect2 an internal utility which invokes the linker.

提交回复
热议问题