A person from England had posted the following code snippet.
Shortly after that, someone made the following response.Code:unsigned char *loadbmp(const char *fname, int *width, int *height) { FILE *fp; int err; unsigned char *answer; /* open file in binary mode */ fp = fopen(fname, "rb"); if(!fp) return 0; /* get all the information we need for the header */ err = loadheader(fp, &width, &height); /* in this code we allocate memory for the raster, and load it. we have to be careful to clean up if we encounter error condtions. */ if(err == 0) { answer = malloc(width * height * 3); if(answer) err = loadraster(fp, answer, width, height); if(err != 0) { free(answer); answer = 0; } } else answer = 0; fclose(fp); }
"Having defined the function as returning an unsigned char* would not
returning one be a good idea? Possibly return answer since otherwise you
have lost the memory? "
I tried asking both of these people, via email to clarify this comment. Neither one responded. So can someone here please elaborate on this comment.



LinkBack URL
About LinkBacks



