[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning a value from a constructor

Steve Holle wrote:
We ran into an interesting problem today. We tried to call the following rtems_libio functions from a c++ constructor :

      rtems_libio_check_fd( fd );
      iop = rtems_libio_iop( fd );

The first and third generated the following errors :

/tcb2/rlc/source/char_available.c:55: returning a value from a constructor
/tcb2/rlc/source/char_available.c:57: returning a value from a constructor

This baffled us for a time until we realized that these two functions were actually macros that contained returns for failure. We solved the problem by calling a subroutine that called the two functions. If the two functions were actually subroutines instead of macros the code would have compiled.

This took me a second to figure out what was going on.
They are actually in libio_.h which is intended to be helper macros for the implementation of the section 2 system calls. Are you getting visibility of this macro through an intentionally public .h file?

Or are you directly including libio_.h?

I know this would be a huge job and probably not worth the time but it would be helpful if it was easy to tell macros from subroutines. One method I've seen in the past is that all macros are capitalized.

That is one way.

Just wanted to get this into the archive in case someone else runs into this problem.

Steve Holle
Link Communications, Inc.
1035 Cerise Rd.
Billings, MT 59101

Joel Sherrill, Ph.D.             Director of Research & Development
joel@OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985