NO

Author Topic: Scope-exit functions  (Read 4402 times)

castor

  • Guest
Scope-exit functions
« on: August 01, 2005, 01:25:55 PM »
Hello Pelle...
Just came up with the idea of some kind of compiler construct (say, pragma) allowing to execute the functions upon the scope exit.
Kinda the #pragma exit but the functions are executed whenever the scope in which that pragmas were put is leaved. Another difference is to allow to pass one or several parameters to the function. Such a scope-exit list could be static code, generated by the compiler (easy way to allow several parameters to the functions). Also it would be nice if the compiler could allow such a contruct to be put into the #define directive, so the programmer could declare the variable and put the deinitializer for it nearby.
The main goal for it is to provide the hook for the programmer to deallocate resources.
I know that this smells cpp-ish but IMHO that would be a nice feature.

Regards,
Andy aka castor

BTW have you been told you have created sweet nice piece of software?... =D>

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Scope-exit functions
« Reply #1 on: August 01, 2005, 11:28:30 PM »
Hello,

There is always the
Code: [Select]

__try { ... } __finally { ... }

way of cleaning up resources. The __finally block will always be executed, no matter how you leave the __try block (normal flow, exception, return statement ...).

Maybe you have some other idea? Do you have some "psudo code" so I understand better what you want...?

...and thanks! :-)

Pelle
/Pelle

Anonymous

  • Guest
Re: Scope-exit functions
« Reply #2 on: August 02, 2005, 05:49:18 AM »
Quote from: "Pelle"
Hello,

There is always the
Code: [Select]

__try { ... } __finally { ... }

way of cleaning up resources.


 :lol: Y'know I almost posted that myself, but thought better of it.

Of course that's what try/finally is for.  Moreover, the exception handling in PellesC is exactly why I picked it over it's many competitors, even a couple of commercial ones.

castor

  • Guest
Re: Scope-exit functions
« Reply #3 on: August 02, 2005, 11:54:31 AM »
Quote from: "Pelle"

There is always the
Code: [Select]

__try { ... } __finally { ... }

way of cleaning up resources. The __finally block will always be executed, no matter how you leave the __try block (normal flow, exception, return statement ...).

Maybe you have some other idea? Do you have some "psudo code" so I understand better what you want...?

Yep, the semantics is exactly the same as for the code in __finally block. The only difference is to implicitly put the function calls into it, so the code for the __finally block is put at the places way before the place of its actual execution.
Yes, I'm a lazy programmer and I'm very accustomed to the destructors called on the scope exit... :roll:

Regards,
Andy

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Scope-exit functions
« Reply #4 on: August 02, 2005, 11:39:52 PM »
I'm almost finished with v4.0, so I'm not doing any major changes to the compiler at this point. I will think about it. Maybe...

Pelle
/Pelle