[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: [rtl] Constructor/Destructor
On Fri, 8 May 1998, Colin Leister wrote:
> Did you guys (Richard/Daniele) ever get the C++ constructor/destructor
> calls to work?
>
All my module have less then 200 lines of code. I was looking for C++ in
module before to get some feature not include in C (fixed point class).
But now it is very unuseful for me so i forgot this idea and all my module
are in C. The real work in my case is in real processes and real-time
stuffs are in module.
But here is an working example.
#define MODULE
#define __KERNEL__
extern "C" {
#include <linux/module.h>
#include <linux/kernel.h>
void * kmalloc(unsigned size, int prio);
void kfree(void * p);
int init_module();
void cleanup_module();
};
void * operator new (unsigned size) { return kmalloc(size,0); }
void * operator new[](unsigned size, unsigned nb) { return
kmalloc(size*nb,0); }
void operator delete (void * p) { kfree(p); }
void operator delete[](void *p) { kfree(p); }
class tata
{
public:
tata() { printk("ctor\n"); }
~tata() { printk("dtor\n"); }
};
tata * p;
int init_module()
{
p = new tata;
return 0;
}
void cleanup_module()
{
delete p;
}
--- [rtl] ---
For more information on Real-Time Linux see:
http://rtlinux.cs.nmt.edu/