码迷,mamicode.com
首页 > 其他好文 > 详细

implicitly declaring function 'malloc' with type void *(unsigned long ) 错误 解决

时间:2016-05-13 10:08:20      阅读:3911      评论:0      收藏:0      [点我收藏+]

标签:

   errror :   implicitly declaring function ‘malloc‘ with type void *(unsigned long )

  1. Be sure to include the correct header file.

    #include <stdlib.h>
    
  2. Casting the return is allowed but frowned upon in C as being unnecessary.

    double* sequence = malloc(...);
    
  3. Consider the follow style as its easier to maintain and IMO, less error prone.

    double* sequence = malloc(numInSeq * sizeof(* sequence));
    
  4. Remember the argument type is size_t may differ in size than int.  size_t is the unsigned integer type of the result of the sizeof operator.

    void *malloc(size_t size);
    
  5. Check the result.

    if (sequence == NULL) Handle_OutOfMemory();
    
  6. Eventually, free the pointer. It is OK to free the pointer even if it has a NULL value.

    free(sequence);
    
  7. If there is a chance sequence will get used agian, best to promptly set its value to NULL.

    free(sequence);
    sequence = NULL;
    
 

implicitly declaring function 'malloc' with type void *(unsigned long ) 错误 解决

标签:

原文地址:http://www.cnblogs.com/lan1x/p/5485705.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!