[ECOS] eCos reference manual needs correction
Paul D. DeRocco
pderocco@ix.netcom.com
Wed Apr 30 12:16:00 GMT 2008
> From: Ilija Stanislevik
>
> The eCos on-line reference manual
> (http://ecos.sourceware.org/docs-2.0/ref/kernel-thread-create.html),
> chapter Thread Entry Points and C++, gives an example which does not work.
> The example states:
> .
> .
>
> fred* object = static_cast<fred*>(objptr);
> .
>
> It is the static cast which makes compiler unhappy. The variable
> object is a pointer, while objptr is of type cyg_addrword_t,
> itself being an unsigned int. Knowing this, it is obvious why the
> compiler complains.
>
> The issue was solved with the 'dangerous' reinterpret_cast
> instead of static _cast:
> .
> .
> fred* object = reinterpret_cast<fred*>(objptr);
> .
>
> There is an other place within the example which needs the same
> intervention. Instead of
> …
> cyg_thread_create( …,
> &fred::static_thread_aux,
> static_cast<cyg_addrword_t>(&instance),
> …);
> …
> I used
> …
> cyg_thread_create( …,
> &fred::static_thread_aux,
> reinterpret_cast<cyg_addrword_t>(&instance),
> …);
> …
>
> Now I wonder if this is a general issue or it is limited to my Starter
> Kit with AT91SAM926x for EB926x Evaluation Boards from Ronetix?
>
> Is there a better, less 'dangerous' way to solve the issue?
>
> Anyway, it seems that the manual needs to be corrected.
It's possible that on some platforms, cyg_addrword_t is defined as void*, in which case static_cast would work. I suspect this was originally written with a C cast, and someone updated it to more "correct" C++ at some point.
But a reinterpret_cast is the correct thing to do. There's certainly no safer way to do it, since it really is about making the bits in a cyg_addrword_t into a pointer, to undo another complementary cast that occurred earlier.
--
Ciao, Paul D. DeRocco
Paul mailto:pderocco@ix.netcom.com
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
More information about the Ecos-discuss
mailing list