[14] in 6.033-lab
Re: Pointer Rules
daemon@ATHENA.MIT.EDU (Patrick McCormick)
Mon Mar 17 03:50:10 1997
To: 6.033-lab@MIT.EDU
In-Reply-To: Your message of "Mon, 17 Mar 1997 03:42:52 EST."
<199703170842.DAA07448@xenophon.mit.edu>
Date: Mon, 17 Mar 1997 03:49:53 EST
From: Patrick McCormick <pmccormi@MIT.EDU>
Oops, there's a minor C mistake in my last post. Apologies.
The code:
void alloc_buffer(char *buf)
{
buf = (char*)malloc(sizeof(BUF_LEN * sizeof(char)));
}
should be:
void alloc_buffer(char *buf)
{
buf = (char*)malloc(BUF_LEN * sizeof(char));
}
Where it says:
To do things right, you can either return the new pointer value, or
use a double-pointer. Returning the new pointer value is
straightforward.
char* alloc_buffer() {
buf = (char*)malloc(sizeof(BUF_LEN * sizeof(char)));
}
should read:
char* alloc_buffer() {
return (char*)malloc(BUF_LEN * sizeof(char));
}
--Pat