I was wondering if this function is both compatible with a multitude of popular compilers
Compilers compile code. system("clear")
is compatible with the compiler.
will I run into problems if I use it multiple times in one project)?
You will run into the exact same problems when you use it once. I would expect it to be "safe" to use multiple times, it just clears the terminal.
I was wondering if system("clear") had that kind of requirement as well
There are multiple requirements for system
:
- the standard library has to provide
system()
function.
- the system has to have a shell
- that shell can be executed
These are just not true on any microcontroller.
There are requirements for a shell to have a clear
command, that command has to exist. This is not true on small operating systems or on any Linux systems without installed ncurses, etc.
Finally, the command clear
has to do the right thing. This means you have to have something-compliant terminal that clear
knows a way to communicate here. This implies multiple levels - on Linux, there is a whole database that solely contains what to send on which terminal to do what. On Linux from ncurses clear
queries that whole database, finds terminal configuration depending on $TERM
environment variable, finds the sting to send to clear the string for that terminal, and finally sends it. On any other system, this may work anyhow differently.
Instead, consider just using ncurses in your project if you depend on terminal capabilities.