nullplan wrote:
Why do people just love to write loops? Assuming text_buffer is an array of char, bloodline's code can be simplified down entirely like this:
Code:
void textbuffer_scroll_one_line(void) {
memmove(text_buffer, text_buffer + WIDTH, (HEIGHT - 1) * WIDTH);
memset(text_buffer + (HEIGHT - 1) * WIDTH, ' ', WIDTH);
}
And if it isn't, then the first line remains almost valid (requiring a multiplication with the size of text_buffer's base type in the size argument), and the second line does have to be replaced with that loop. But at least the memmove is out of the way.
In my defence, the function I posted was written before I had written any memory manipulation functions, but you are right, it does make sense to use them, if you have them... I suspect the OP does not have them at this time.
Also I thought OP might benefit from seeing the more verbose algorithm.
Quote:
bloodline wrote:
I also think you might be making more work for yourself using C++ at this time.
Erm, you know you can write exactly the same thing in C++, and exactly the same criticism is valid there, right?
I wasn't criticising his choice of language, rather that using an OOP design pattern is going to take more effort to get right at this stage, and with very little gain. I think he might learn more easily working closer to the way the hardware actually works.
Quote:
Besides, if your code is C and not C++, you should look into the difference between declaring a function with an empty argument list, and with a void argument. In C++ there is no difference, and indeed some people are pushing empty argument lists into style guides, but in C there is one, and not knowing it can break your code.
Well, the function I posted is actually the definition, the declaration is in the header file, but you do make a good point! I do sometimes mix up C and C++ language features.