errror : implicitly declaring function ‘malloc‘ with type void *(unsigned long )
- Be sure to include the correct header file.
#include <stdlib.h>
- Casting the return is allowed but frowned upon in C as being unnecessary.
double* sequence = malloc(...);
- Consider the follow style as its easier to maintain and IMO, less error prone.
double* sequence = malloc(numInSeq * sizeof(* sequence));
- Remember the argument type is
size_t
may differ in size thanint
.size_t
is the unsigned integer type of the result of thesizeof
operator.void *malloc(size_t size);
- Check the result.
if (sequence == NULL) Handle_OutOfMemory();
- Eventually, free the pointer. It is OK to free the pointer even if it has a
NULL
value.free(sequence);
- If there is a chance
sequence
will get used agian, best to promptly set its value toNULL
.free(sequence); sequence = NULL;
implicitly declaring function 'malloc' with type void *(unsigned long ) 错误 解决
时间: 2024-11-05 18:31:06