delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/30/03:01:53

Message-Id: <199712300757.JAA03567@ankara.duzen.com.tr>
Comments: Authenticated sender is <mitch AT ankara DOT duzen DOT com DOT tr>
From: "S. M. Halloran" <mitch AT duzen DOT com DOT tr>
Organization: User RFC 822- and 1123-Compliant
To: djgpp AT delorie DOT com
Date: Tue, 30 Dec 1997 09:58:05 +0200
MIME-Version: 1.0
Subject: Re: What's wrong????
In-reply-to: <34A84506.B7E@cam.org>

On 29 Dec 97, Vic was found to have commented thusly:

> Rune Lanton wrote:
> > *file_buffer = malloc((file_size)+512);
> this is your problem. You should read more about pointers in a C book.
> if you have this: 
> char *p;
> p is a pointer to char. It is unitialised, so it can point to any
> location in memory.
> *p is the VALUE of the variable pointed to.
> so if you say p=&variable, *p=5 is equivalent to variable=5;
> when you say
>  *file_buffer = malloc((file_size)+512);
> you malloc some memory then you write the ADRESS of the memory block AT
> the ADRESS in memory pointed by p;
> that should be
>  >> file_buffer = malloc((file_size)+512); << without the asterix.
> Hope this was clear enough...

He is also missing some standard header files, namely the one that 
declares malloc().  Your compiler will assume it returns an integer 
when, in fact, it returns (under ANSI C--someone correct me) a void 
pointer (void *).  The act of the assignment will cast it to the 
pointer of the proper data type.

You should have been warned that this function was missing its 
prototype;  perhaps you were and ignored it.  A very, very wise rule 
in C programming is to make sure the compiler warnings regarding 
function prototypes are all turned on, and that you deal with every 
warning until you get no more warnings.  If you are not really aware 
of the value of fully prototyped functions and of making sure you 
turn on and deal with a particular subset of important compiler 
warnings (not just errors), then reply to this thread with "Why?" or 
something like that and those who have a great deal of experience 
with crashing programs and wild pointers will expound.

Mitch Halloran
Research (Bio)chemist
Duzen Laboratories Group
Ankara   TURKEY
mitch AT duzen DOT com DOT tr

other job title:  Sequoia's (dob 12-20-95) daddy

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019