D
Dave
I've got a problem. I can't seem to figure out how to make a char*
buffer for use as a socket buffer using operator 'new' in it's basic
form. In affect, I need to allocate space dynamically in memory
pointed to by a char*.
It doesn't appear I can use 'char buffer[length + 5];' and then pass
buffer around as a char*. The compiler complains about being unable
to evaluate the non-constant term between the brackets.
So I thought I might be able to do something like this with new:
int length += 5;
char* buffer = new char[length];
It appears to work - at least my 1995 vintage Unix 10.20 compiler
doesn't complain about the non-constantness. But my program is
seriously broken. It looks like a buffer over-run with garbage in the
stream. I have also wondered if my declaration did work but my use is
wrong. Perhaps I really have a char** and not a char*. Do I need to
terminate the message with a \0? What am I doing wrong and how can I
achieve a dynamic allocation like this?
Dave
buffer for use as a socket buffer using operator 'new' in it's basic
form. In affect, I need to allocate space dynamically in memory
pointed to by a char*.
It doesn't appear I can use 'char buffer[length + 5];' and then pass
buffer around as a char*. The compiler complains about being unable
to evaluate the non-constant term between the brackets.
So I thought I might be able to do something like this with new:
int length += 5;
char* buffer = new char[length];
It appears to work - at least my 1995 vintage Unix 10.20 compiler
doesn't complain about the non-constantness. But my program is
seriously broken. It looks like a buffer over-run with garbage in the
stream. I have also wondered if my declaration did work but my use is
wrong. Perhaps I really have a char** and not a char*. Do I need to
terminate the message with a \0? What am I doing wrong and how can I
achieve a dynamic allocation like this?
Dave