[okl4-developer] iguana cc
Jorge Torres
jorge.torres.maldonado at gmail.com
Tue May 29 18:49:59 EST 2007
Hi,
Thank you both Alex and Ben, I now have a new operator, having a picocpp.h,
was simpler than I thought, here is the code, just in case someone ever
wants it (it seems to work):
/* ---- okl4_release_1.4.1.1/libs/c/picocpp.h---- */
///////////////////////
//PICOCPP for iguana
//what: just new and its combinations
///////////////////////
#ifndef __PICOCPP_H__
#define __PICOCPP_H__
extern "C" {
#include <stdlib.h>
}
#define XNEW(A)\
void *p=0;\
p=(void*)malloc(A);\
return p;
#define XNEW_NOTHROW\
void *p=0; \
return p;
/*FIXME: THERE SHOULD BE A MEMORYSPACE std*/
struct nothrow_t {};
extern const nothrow_t nothrow;
inline void* operator new(size_t a) {
XNEW(a)
}
inline void* operator new[](size_t a) {
XNEW(a)
}
inline void operator delete (void *p){
free(p);
}
inline void operator delete[] (void *p){
free(p);
}
inline void* operator new (size_t size, nothrow_t &){
XNEW_NOTHROW
}
inline void* operator new[] (size_t size, nothrow_t &nt){
XNEW_NOTHROW
}
inline void operator delete(void* v, nothrow_t &){
return;
}
inline void operator delete[](void* v, nothrow_t &nt){
return;
}
#endif
On 5/27/07, Alex Webster <alexw at ok-labs.com> wrote:
>
> Hi Jorge,
>
> All you need to do is define a global operator new, and make sure that
> it gets linked with your program. You could put it in a mini libc++.
> Of course you probably won't be able to throw exceptions for out of
> memory, unless you implement the necessary runtime support.
>
> Don't forget to implement the array versions (i.e., new[] and delete[]),
> the nothrow versions, the placement versions and all the relevant
> combinations of these.
>
>
> Alex
>
> On Sun, 2007-05-27 at 21:33 -0400, Jorge Torres wrote:
> > Hi Ben,
> >
> > Thank you, your extern C wraping advise was exactly what I was
> > looking for, if I only knew this a few minutes ago, I wouldn't have
> > cloned stdio.h with extern C for every function, hahaha :), not a big
> > deal anyway.
> >
> > The only thing I miss about C++ runtime, its the new method for memory
> > allocation, I think this is a little off topic for okl4, so feel free
> > to ignore this: I'm trying to get one NEW for my self, but for now the
> > best solution I've came up with was adding a new operator for each
> > class:
> >
> > #define NEW(TYPE) void * operator new (size_t a){ \
> > void *p; \
> > p=(TYPE*)malloc(sizeof(TYPE)); \
> > return p; \
> > }
> >
> > class bla{
> > .
> > .
> > public:
> > NEW(bla);
> > .
> > .
> > };
> > But I can't figure out how to make this in a much more general way,
> > something like inline new.
> > problem I have is on how can one guess what is itself's type so one
> > can do something like:
> > void *p=(guessed_itselftype *)malloc(sizeof(guessed_itselftype));
> > Anyhow, if someone has done this, I'll be happy to know how.
> >
> >
> > Thanks again,
> >
> > Jorge
> >
> >
> > On 5/27/07, Ben Leslie <benno at ok-labs.com> wrote:
> > On Fri May 25, 2007 at 04:54:20 -0400, Jorge Torres wrote:
> > >Hi okl4.org,
> > >
> > >I tried to change the example/manyelfsegs/src/main.c to
> > main.cc, and I had
> > >some linking problems with stdio.h, does someone knows what
> > is the correct
> > >way of doing this (iguana style :), my temporal solution was:
> > >-----
> > >at this new example/manyelfsegs/src/main.cc
> > >#define CTOCPP extern "C"
> > >#include <stdio.h>
> > >------
> > >and at libs/c/include/stdio.h
> > >#ifndef CTOCPP
> > >#define CTOCPP
> > >#endif
> > >.
> > >.
> > >CTOPCPP int printf(const char *, ...);
> > >------
> >
> >
> > Hi Jorge,
> >
> > We don't really have a C++ runtime, but, if you are trying to
> > use the
> > C library runtime, within a C++ program you should wrap the
> > include
> > within an extern C block, e.g:
> >
> >
> > """
> >
> > extern C {
> > #include <stdio.h>
> > }
> >
> >
> > """
> >
> > _______________________________________________
> > Developer mailing list
> > Developer at okl4.org
> > https://lists.okl4.org/mailman/listinfo/developer
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.okl4.org/pipermail/developer/attachments/20070529/03d9be16/attachment.htm
More information about the Developer
mailing list