C++ Does not Compile on PowerPC

Joel Sherrill joel.sherrill at OARcorp.com
Fri May 4 20:22:19 UTC 2012


Hi

The stdint.h in gcc 4.7.0 has changed and made constants
like UINT32_MAX hidden to C++ code by default.

In file included from ../../.././psim/lib/include/rtems/score/isr.h:361:0,
                  from ../../.././psim/lib/include/rtems/score/object.h:22,
                  from ../../.././psim/lib/include/rtems/score/mppkt.h:38,
                  from ../../.././psim/lib/include/rtems/score/thread.h:92,
                  from ../../.././psim/lib/include/rtems/score/heap.h:22,
                  from ../../.././psim/lib/include/rtems/rtems/types.h:25,
                  from ../../.././psim/lib/include/rtems.h:48,
                  from 
../../.././psim/lib/include/rtems++/rtemsStatusCode.h:22,
                  from ../../.././psim/lib/include/rtems++/rtemsEvent.h:23,
                  from 
../../../../../rtems/c/src/librtems++/src/rtemsEvent.cc:19:
../../.././psim/lib/include/rtems/score/isr.inl: In function 'bool 
_ISR_Is_vector_number_valid(uint32_t)':
../../.././psim/lib/include/rtems/score/isr.inl:38:22: error: 
'UINT32_MAX' was not declared in this scope

UINT32_MAX is referenced from score/cpu/powerpc/.../cpu.h and the code
in question has not changed in a long time. When gcc was upgraded from
  4.6.3 to 4.7.0, this broke and it was not detected at the time.

The very simple answer is that in 4.7.0, the "size int MAX" constants are
inside this:

#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

and they were not protected that way in 4.6.3. This is a PowerPC issue
which renders any C++ code that includes rtems.h unable to compile.


The solution I came up with which works and seems to be the least
invasive solution is to define __STDC_LIMIT_MACROS when compiling C++
in cpukit/score/cpu/powerpc/rtems/score/types.h. This let librtems++
compile but the C++ samples still did not build

=============================================
diff --git a/cpukit/score/cpu/powerpc/rtems/score/types.h 
b/cpukit/score/cpu/powerpc/rtems/score/types.h
index 828a363..95a4a89 100644
--- a/cpukit/score/cpu/powerpc/rtems/score/types.h
+++ b/cpukit/score/cpu/powerpc/rtems/score/types.h
@@ -36,6 +36,13 @@
  #ifndef _RTEMS_SCORE_TYPES_H
  #define _RTEMS_SCORE_TYPES_H

+/*
+ *  GCC 4.7.0 and newer hide the UINTxx_MAX/MIN macros incide
+ *  a define for C++.
+ */
+#if defined(__cplusplus)
+ #define __STDC_LIMIT_MACROS
+#endif
  #include <rtems/score/basedefs.h>

  #ifndef ASM
=============================================

Any thoughts on how to address this?

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





More information about the devel mailing list