This is the mail archive of the ecos-discuss@sources.redhat.com 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: (const void) as return type


On Wed, Jul 09, 2003 at 05:52:07PM +0200, Andrew Lunn wrote:
> On Wed, Jul 09, 2003 at 05:34:47PM +0200, Christoph Csebits wrote:
> > hi,
> > 
> > in infra/current/include/cyg_ass.h line 193
> > 
> > the cyg_check_func_ptr function expects
> > a pointer to a function with "const void"
> > as return type.
> > 
> > Does it make sense to have a function
> > returning a _const_ void ?
> 
> externC cyg_bool cyg_check_func_ptr(const void (*ptr)(void));
> 
> # define CYG_CHECK_FUNC_PTRC( _ptr_ )                       \
>          CYG_MACRO_START                                    \
>          if ( !cyg_check_func_ptr((const void (*)(void))(_ptr_))) \
>              CYG_ASSERT_DOCALL("function pointer (" #_ptr_ ") is valid"); \
>          CYG_MACRO_END
>  
> #else // CYGDBG_USE_ASSERTS
> 
> It does not really matter. It does not call the function, it just
> needs to know the address of it to make sure its in the code
> section. All this casting is just to turn some random function into a
> specific type which can then be passed into cyg_check_func_ptr without
> compiler warnings. But this obviously fails on 3.2.2 :-(
> 
> I've always found function pointers confusing, but doesn't that * mean
> its a const void *. ie its a const pointer to a non const void.

No. 
const void (*)(void) means we have a pointer
to a function taking void as its only argument and
returning something that is const void.

i think its not really reasonable to give void the
qualifier const in this context: 

For example an example:

void foo(void);         // a function returning nothing.
const void foo2(void);  // a function returning nothing, but
                        // that nothing is const. 

BTW i would prefer something like that:
 
typedef void (*func_ptr_void)(void);
externC cyg_bool cyg_check_func_ptr(func_ptr_void);
 
# define CYG_CHECK_FUNC_PTRC( _ptr_ )                       \
         CYG_MACRO_START                                    \
         if ( !cyg_check_func_ptr((func_ptr_void)(_ptr_))) \
             CYG_ASSERT_DOCALL("function pointer (" #_ptr_ ") is valid"); \
         CYG_MACRO_END
 
#else // CYGDBG_USE_ASSERTS


>  
> > BTW:
> > powerpc-eabi-gcc (GCC) 3.2.2 with -W option
> > produces the warning: type qualifiers ignored on function return type
> 
> What exactly is causing the problem?  What is the value of _ptr_.

const void as return type is not permitted for my compiler.
(const is the type qualifier, void is the return type...)

removing const results in no warnings.
Christoph

-- 

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


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