A
amer.terzic
Here's what my code is supposed to do (it seems to work fine)
Take a char* array and remove a first character from it....as simple as
that.
The mentioned char* array is a 'global' var shared among threads.
Declared as : char* buffer = (char*) malloc(bufferSize)
(later I changed it to use C++ 'new', but it does the same thing)
Then I have a function declared as :
void* readBuffer(void*)
{
blah blah
char* copy=malloc and stuff ;
copy=buffer; // would YOU do it this way ?
blah (do stuff with copy )
*buffer++; /* so now buffer lost its first element
at buffer[0] */
}
Here's my question:
How bad is this code when it comes to style?
Does it make sense to do *buffer++ to cut the first character
off ?
It works just fine, but I'd like to know if something like this would
be acceptable in the real world ( as opposed to school assignment)?
Should I 'clean up' after myself (buffer[0] from before now sits in
memory unused) ?
How would I clean up after myself ?
The reason I did not use strncpy or anyother 'built-in' function is due
to restrictions in the problem itself.
I'd appreciate a comment.
Take a char* array and remove a first character from it....as simple as
that.
The mentioned char* array is a 'global' var shared among threads.
Declared as : char* buffer = (char*) malloc(bufferSize)
(later I changed it to use C++ 'new', but it does the same thing)
Then I have a function declared as :
void* readBuffer(void*)
{
blah blah
char* copy=malloc and stuff ;
copy=buffer; // would YOU do it this way ?
blah (do stuff with copy )
*buffer++; /* so now buffer lost its first element
at buffer[0] */
}
Here's my question:
How bad is this code when it comes to style?
Does it make sense to do *buffer++ to cut the first character
off ?
It works just fine, but I'd like to know if something like this would
be acceptable in the real world ( as opposed to school assignment)?
Should I 'clean up' after myself (buffer[0] from before now sits in
memory unused) ?
How would I clean up after myself ?
The reason I did not use strncpy or anyother 'built-in' function is due
to restrictions in the problem itself.
I'd appreciate a comment.