Hi Norman,
You are right - these examples don't use stdlib ...
But this wasn't what I want to say.
I want to say that is possible to write C++ modules, which
are useable in the RTLinux.
Now I read the other mails in the list, and now I know that C++
code is possible but not recommend and supporte by RTLinux.
Thanks !!
MIchael
-----Original Message-----
From: Dresner, Norman A. [SMTP:[EMAIL PROTECTED]]
Sent: Tuesday, November 27, 2001 4:24 PM
To: Back Michael (extern)
Subject: RE: [rtl] Using STL (Standard Template Library)
Michael.
I'm including just below this typed message the files hello.cpp,
rtl_cpp.c
and rtl_cpp.h from my system. It's clear from these files that the
example
is using rtl_printf() and not any of the stdlib functions.
Norm
BEGIN INCUDED CODE HERE
<><><><><><><><><><> THIS IS HELLO.CPP <><><><><><><><><><><>
#include <rtl_cpp.h>
pthread_t thread;
class A {
protected:
int a;
public:
virtual void print()=0;
A() { a = 1; rtl_printf("initializing A\n");}
virtual ~A() { rtl_printf("uninitializing A\n"); }
};
class B : public A
{
public:
B() { a = 1; rtl_printf("initializing B\n");}
~B() { rtl_printf("uninitializing B\n");}
virtual void print() { rtl_printf("B::print: %d\n", a); }
};
void * start_routine(void *arg)
{
struct sched_param p;
p . sched_priority = 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
pthread_make_periodic_np (pthread_self(), gethrtime(),
500000000);
while (1) {
pthread_wait_np ();
rtl_printf("I'm here; my arg is %x\n", (unsigned)
arg);
}
return 0;
}
B a;
A *ptr_b;
int init_module(void) {
__do_global_ctors_aux();
ptr_b = new B;
ptr_b -> print();
return pthread_create (&thread, NULL, start_routine, 0);
}
void cleanup_module(void) {
pthread_delete_np (thread);
delete ptr_b;
__do_global_dtors_aux();
}
<><><><><><><><><><> THIS IS RTL_CPP.C <><><><><><><><><><><>
/*
* RTLinux C++ support
* Written by Michael Barabanov, [EMAIL PROTECTED]
* (C) 2000 FSMLabs, GPL
*
* Parts of this code are based on glibc, copyright FSF Inc
*/
#include <rtl_printf.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/module.h>
void __pure_virtual (void)
{
rtl_printf("__pure_virtual called\n");
}
void __this_fixmap_does_not_exist(void)
{
rtl_printf("__this_fixmap_does_not_exist called\n");
}
/* the following is from glibc, Copyright FSF Inc */
void
__assert_fail (const char *assertion, const char *file, unsigned int
line,
const char *function)
{
/* Print the message. */
(void) rtl_printf ("%s:%u: %s%sAssertion `%s' failed.\n",
file, line,
function ? function : "", function ? ": " :
"",
assertion);
}
#ifdef __i386__
typedef unsigned long u_int32_t;
typedef long int32_t;
typedef union
{
double value;
struct
{
u_int32_t lsw;
u_int32_t msw;
} parts;
} ieee_double_shape_type;
#endif
#define EXTRACT_WORDS(ix0,ix1,d) \
do { \
ieee_double_shape_type ew_u;
\
ew_u.value = (d);
\
(ix0) = ew_u.parts.msw;
\
(ix1) = ew_u.parts.lsw;
\
} while (0)
int __isnan(double x)
{
int32_t hx,lx;
EXTRACT_WORDS(hx,lx,x);
hx &= 0x7fffffff;
hx |= (u_int32_t)(lx|(-lx))>>31;
hx = 0x7ff00000 - hx;
return (int)((u_int32_t)(hx))>>31;
}
<><><><><><><><><><> THIS IS RTL_CPP.H <><><><><><><><><><><>
/*
* rtlcpp.h - C++ support for RTL
* Michael Barabanov, <[EMAIL PROTECTED]>
*
* Ideas and code from David Olofson, Yunho Jeon and myself
*/
#ifndef __KERNELCPP__
#define __KERNELCPP__
#ifdef __cplusplus
extern "C" {
#endif
#define new _new
#define virtual _virtual
#define NULL 0
#include <linux/kernel.h>
#include <linux/module.h>
#include <rtl_sched.h>
#include <rtl_fifo.h>
#include <rtl_time.h>
#include <pthread.h>
#undef new
#undef virtual
#ifdef __cplusplus
}
#endif
extern "C" {
void *kmalloc(unsigned size, int prio);
void kfree(const void *p);
};
extern "C" {
int __do_global_ctors_aux();
int __do_global_dtors_aux();
}
void *operator new (unsigned size) {
return kmalloc(size,0);
}
void *operator new[] (unsigned size) {
return kmalloc(size,0);
}
void operator delete (void *p) {
kfree(p);
}
void operator delete[] (void *p) {
kfree(p);
}
extern "C" {
int init_module();
void cleanup_module();
}
#endif
END INCLUDED CODE HERE
> -----Original Message-----
> From: Back Michael (extern) [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, November 27, 2001 9:54 AM
> To: Dresner, Norman A.; '[EMAIL PROTECTED]'
> Subject: RE: [rtl] Using STL (Standard Template Library)
>
> Sorry,
> so wie have different examples.
> My example use two objects called rtl_cpp.o ( rtl_cpp.c)
> and app.o (hello.cpp).
> Both are insmod in the Kernel !
> An it work !
> Additional I had read in the web that the USB linux device driver
> is developed in c++.
> Michael
>
>
>
> > Not quite. If you look carefully at the example, you'll see
that all of
> > the
> > C++ code is in the user-domain and all of the kernel-code is in
pure C.
> > All
> > that example proves is that it's possible to use RTLinux with
C++ user
> > programs.
> >
> > Norm
> >
> >
> > > > On Thu, 22 Nov 2001, Sharon Oren wrote:
> > > >
> > > > >
> > > > > Hi,
> > > > > I'm porting my application from Linux (in user mode)
ro
> > RTLinux (as
> > > > > a task).
> > > > > My code is in c++ and using STL.
> > > >
> > > > C++ is can of worms at system level. Do NOT use it. Even MS
Windoz
> > > > uses C at kernel level.
> > > >
> > > Hi,
> > > this is not truly right.
> > > With RTL it is possible to use C++
> > > ../examples/cpp
> > > put it is not easy!
> > > I think using STl is not possible !!
> > > -- [rtl] ---
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/