Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void function()
- {
- {
- int i = 0;
- i = i + 1;
- }
- {
- int k = 0;
- k = k + 1;
- }
- }
- void function()
- {
- {
- std::ofstream out( "file.txt" );
- out << "some datan";
- }
- // You can be sure that "out" is closed here
- }
- void function() {
- // ...
- {
- // lock some mutex.
- mutex_locker lock(m_mutex);
- // ...
- }
- // ...
- }
- void function() {
- // set up timer A
- {
- int config = get_config(TIMER_A);
- // ...
- }
- // set up timer B
- {
- int config = get_config(TIMER_B);
- // ...
- }
- }
- glPushMatrix();
- {
- glTranslate(...);
- glPushMatrix();
- {
- glRotate(...);
- // draw some stuff
- }
- glPopMatrix();
- // maybe draw some more stuff
- }
- glPopMatrix();
- switch (i)
- {
- case 0 :
- int j = 0; // error!
- break;
- switch (i)
- {
- case 0 :
- {
- int j = 0; // ok!
- }
- break;
- class ExpensiveObject {
- public:
- ExpensiveObject() {
- // acquire a resource
- }
- ~ExpensiveObject() {
- // release the resource
- }
- }
- int main() {
- // some initial processing
- {
- ExpensiveObject obj;
- // do some expensive stuff with the obj
- } // don't worry, the variable's scope ended, so the destructor was called, and the resources were released
- // some final processing
- }
- {
- int[] myArray = new int[1000];
- ... // Do some work
- }
- // The garbage collector can now reclaim the memory used by myArray
- int a=25;
- int b=30;
- { //at this point, a=25, b=30
- a*=2; //a=50, b=30
- b /= 2; //a=50,b=15
- int a = b*b; //a=225,b=15 <--- this new a it's
- // declared on the inner scope
- }
- //a = 50, b = 15
- int main() {
- /* Blah blah blah. */
- {
- int i;
- for (i = 0; i < 10; ++i) {
- }
- }
- }
- int MyClass::foo()
- {
- // stuff uncritical for multithreading
- ...
- {
- someKindOfScopeLock lock(&mutexForThisCriticalResource);
- // stuff critical for multithreading!
- }
- // stuff uncritical for multithreading
- ...
- }
Add Comment
Please, Sign In to add comment