Re: gcc option for constructor and destructors



On Apr 9, 7:26 am, sinbad <sinbad.sin...@xxxxxxxxx> wrote:
i want to write a constructor and destructor function in c for each of
the function.
I should register a routines which will be called before calling the
function and destructor before actual return of the original function.
Does gcc provides anything like this.

gcc allows you to put a cleanup attribute on one of the
automatic variables which would give you the destructor.
http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Variable-Attributes.html#Variable%20Attributes

To simulate a constructor, you can overload the function
by giving your constructor the same name as the
function and then use dlsym( RTLD_NEXT,...) to
call the function itself.

You're probably better off just modifying
the function to start by calling your constructor/initializer
and end by calling the destructor.
.



Relevant Pages

  • Re: Unusual usage of IUknown
    ... ptA = new A; ... calling V constructor, szData=V ... calling A destructor, szData=A ...
    (microsoft.public.vc.language)
  • Re: Unusual usage of IUknown
    ... char * szData; ... calling V constructor, szData=V ... calling A destructor, szData=A ...
    (microsoft.public.vc.language)
  • Re: [C++] ctors & dtors
    ... (Use and Finish could be named constructor and destructor, ... I tried calling ~foo() directly and it crashed. ...
    (comp.programming)
  • Re: Shutdown order
    ... Thomas Mlynarczyk wrote: ... Where am *I* calling the destructor in my code? ... Like a constructor, you ...
    (comp.lang.php)
  • Re: gcc option for constructor and destructors
    ... I should register a routines which will be called before calling the ... function and destructor before actual return of the original function. ... Does gcc provides anything like this. ...
    (comp.unix.programmer)