#3384 closed enhancement (fixed)

Prefer int for int32_t

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 5.1
Component: tool/gcc Version: 5
Severity: normal Keywords:
Cc: Blocked By:


Common systems like Linux and FreeBSD define int32_t to int. This means a lot of third party code works well in these cases:

#include <stdint.h>

void f(int32_t);

void f(int);

void g(int32_t *);

void h(void)
        int i;

On RTEMS you get however in C

test.c:5:6: error: conflicting types for 'f'
 void f(int);
test.c:3:6: note: previous declaration of 'f' was here
 void f(int32_t);
test.c: In function 'h':
test.c:12:4: warning: passing argument 1 of 'g' from incompatible pointer type [-Wincompatible-pointer-types]
test.c:7:6: note: expected 'int32_t * {aka long int *}' but argument is of type 'int *'
 void g(int32_t *);

and C++

test.c: In function 'void h()':
test.c:12:4: error: invalid conversion from 'int*' to 'int32_t* {aka long int*}' [-fpermissive]
test.c:7:6: note:   initializing argument 1 of 'void g(int32_t*)'
 void g(int32_t *);

This is due to a Newlib speciality which uses long for int32_t if long is a 32-bit type. To ease the use of third party software in RTEMS we should override this option and use int for int32_t just like the standard host operating systems (e.g. Linux and FreeBSD). Only a small GCC patch is required to do this:

diff --git a/gcc/config/rtems.h b/gcc/config/rtems.h
index 439199d4cbb..9b1408efe6f 100644
--- a/gcc/config/rtems.h
+++ b/gcc/config/rtems.h
@@ -48,3 +48,7 @@
  -latomic -lc -lgcc --end-group %{!qnolinkcmds: -T linkcmds%s}}}"
+/* Use int for int32_t (see stdint-newlib.h).  */
+#undef STDINT_LONG32
+#define STDINT_LONG32 0

Change History (10)

comment:1 Changed on 04/09/18 at 13:39:53 by Joel Sherrill

Just to keep it clean, what if int is 16 bits on the target?

comment:2 Changed on 04/09/18 at 13:46:46 by Sebastian Huber

See newlib-stdint.h in GCC sources:

#define INT32_TYPE (STDINT_LONG32 ? "long int" : INT_TYPE_SIZE == 32 ? "int" : SHORT_TYPE_SIZE == 32 ? "short int" : CHAR_TYPE_SIZE == 32 ? "signed char" : 0)

So, 16-bit targets should not use this option.

comment:4 Changed on 06/14/18 at 05:23:35 by Sebastian Huber

Summary: Change int32_t to intPrefer int for int32_t

comment:5 Changed on 12/11/18 at 07:39:39 by Sebastian Huber <sebastian.huber@…>

In b4e80fb/rtems-source-builder:

5: Update GCC 7.3.0 to 7.4.0

Update #3384.

comment:6 Changed on 12/13/18 at 10:34:46 by Sebastian Huber <sebastian.huber@…>

In 258129e/rtems-source-builder:

5: Fix x86_64 GCC 7.4.0 build

Update #3384.

comment:7 Changed on 01/29/19 at 08:22:22 by Sebastian Huber <sebastian.huber@…>

In 4f3a253/rtems:

psxtmtests: Fix format warnings

Update #3384.

comment:8 Changed on 12/12/19 at 23:11:05 by Joel Sherrill

Can this be closed?

comment:9 Changed on 12/13/19 at 06:07:14 by Sebastian Huber

Resolution: fixed
Status: assignedclosed

comment:10 Changed on 12/13/19 at 06:07:28 by Sebastian Huber

Version: 5
Note: See TracTickets for help on using tickets.