4 ms·
Global variables aren't quite as evil as is made out, in the context of an application like a shell. It's better to think of the shell process as a big fat obje
by barrkel 12y ago
Global variables aren't quite as evil as is made out, in the context of an application like a shell. It's better to think of the shell process as a big fat object instance, which gets forked when it does stuff. It's not ideal, but when the globals are appropriately scoped to translation units (i.e. static, not extern), it's usually not too bad to maintain. Each module acts a bit like a singleton.
Snprintf, implemented as a library function, is also a lot (like 1000x) slower than strcpy; however, I don't condone use of strcpy.
- andrewchambers 12y agoExactly, well designed cli programs are themselves already a self contained object. The global variables are more like members to this instance of the program.