??? 03/17/05 21:54 Read: times |
#89884 - file-scope globals Responding to: ???'s previous message |
Donald Catto said:
"I was told "we do not use globals""
Yuck. Either they were C++ programmers or they hadn't read K+R. Seriously, I've don't think I've ever seen a substantial piece of code that didn't use at least 'local globals', ie statics with file scope. I agree. "Local globals" are excellent way of faking a C++ private member variable. Imagine a C source file that contains all functions necessary to deal with a particular feature of your gizmo. Perhaps there's a variable or two that may be manipulated by these functions but the larger program doesn't need to know them. Make 'em file scope. They can't be accessed by functions in other sources. I think we had a discussion here about whether or not such variables should be declared as static, and the answer was "Yes." -a |