Re: Object Oriented Linux

From: H. Peter Anvin (hpa@zytor.com)
Date: Thu Jul 13 2000 - 00:05:35 EST


Followup to: <396D4239.B9BA3781@uow.edu.au>
By author: Andrew Morton <andrewm@uow.edu.au>
In newsgroup: linux.dev.kernel
>
> It was a proof-of-concept. Here ya go:
>
> #define GFP_ATOMIC 1
> #define GFP_KERNEL 2
>
> typedef unsigned int size_t;
>
> extern "C" void *kmalloc(size_t size, int flags);
>
> char gfp_atomic[1];
> char gfp_kernel[1];
>
> inline void *operator new[](size_t size, char *where)
> {
> if (where == gfp_atomic)
> return kmalloc(size, GFP_ATOMIC);
> else if (where == gfp_kernel)
> return kmalloc(size, GFP_KERNEL);
> return 0;
> }
>
> char *foo(int n)
> {
> return new (gfp_atomic) char[n];
> }
>
>
> > Yes, usually C++ compiler can do choices
> > of that kind. And that works for normal userland stuff. Here it's not an
> > option.
>
> But it's fun trying.
>

Well, just do:

inline void * operator new [] (size_t size, int flags)
{
        return kmalloc(size, flags);
}

However, note that the kernel doesn't support static constructors or
destructors, for example. So yes, you can use a C++ compiler if you
insist (and rewrite the Makefiles accordingly), but it's going to be a
relatively crippled version.

The main reason that the kernel doesn't support C++ is that it is
painful enough to deal with multiple versions of gcc. Throwing a mix
of C and C++ into it would make it an even worse nightmare.

        -hpa

-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:16 EST