This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: eCos reference manual needs correction


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]