From: "panda.trooper" <panda.trooper@protonmail.com>
To: Jon Beniston <jon@beniston.com>
Cc: "newlib@sourceware.org" <newlib@sourceware.org>
Subject: RE: [EXTERNAL]: Re: Why int32_t is long int on 32 Bit Intel?
Date: Fri, 28 Jul 2023 21:42:43 +0000 [thread overview]
Message-ID: <mbDd8IERY7M0G1lBn5FywuMKfPvSzWZhqLa1QfC7m5sX0T93-Ck-kM_OD2atJdTl8PMxOiRfuwo_JIspF53B4Fj4wqHz-qINH6bYBV-wzN8=@protonmail.com> (raw)
In-Reply-To: <0e3601d9c191$646f6160$2d4e2420$@beniston.com>
Hi Jon,
you are right, in recent GCC/newlib combinations it is GCC who decides by means of setting __INT32_TYPE__, and newlib takes whatever is defined in __INT32_TYPE__. However, in older newlib versions this was not the case. In the good old days the decision was made like this (newlib/libc/include/stdint.h in newlib version 1.18):
/* Check if "long" is 64bit or 32bit wide */
#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
#define __have_long64 1
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
#define __have_long32 1
#endif
[...]
#if __have_long32
typedef signed long int32_t;
typedef unsigned long uint32_t;
#define __int32_t_defined 1
#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL
typedef signed int int32_t;
typedef unsigned int uint32_t;
#define __int32_t_defined 1
[...]
Please notice "&& !defined(__SPU__)", which is an very interesting exception from the default case. In gcc/config/newlib-stdint.h you find references to this in form of the comment (just from before your excerpt):
/* newlib uses 32-bit long in certain cases for all non-SPU
targets. */
#ifndef STDINT_LONG32
#define STDINT_LONG32 (LONG_TYPE_SIZE == 32)
#endif
So the roots of this decision are in the history of newlib. I also assumed that those people who created gcc/config/newlib-stdint.h have quite some stakes in newlib (or the other way around). That's why I asked in this community.
Your explanation with Turbo C is also plausible. Thanks for that interesting insight.
One final question: do you know what "SPU" means in this context and why it is an exceptional case?
Cheers,
Zoltan
------- Original Message -------
On Friday, July 28th, 2023 at 22:23, Jon Beniston <jon@beniston.com> wrote:
> > So again, just out of curiosity: what is the reason using long as int32_t on an architecture where int is suitable, too?
>
>
> Long ago, there were 32-bit x86 compilers where int was 16-bit (E.g. Turbo C).
>
> Also, are you sure it isn't gcc that's determining the type of int32_t rather than Newlib? I've not used i686-elf-gcc, but for some targets newlib defines int32_t based on INT32_TYPE which is defined by gcc:
>
> In gcc/config/newlib-stdint.h
>
> #ifndef STDINT_LONG32
> #define STDINT_LONG32 (LONG_TYPE_SIZE == 32)
> #endif
> ...
> #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)
>
> Cheers,
> Jon
next prev parent reply other threads:[~2023-07-28 21:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 11:55 panda.trooper
2023-07-27 23:13 ` Brian Inglis
2023-07-28 8:06 ` panda.trooper
2023-07-28 13:23 ` Anders Montonen
2023-07-28 14:15 ` Joel Sherrill
2023-07-28 15:49 ` [EXTERNAL]: " Mike Burgess
2023-07-28 16:11 ` Stefan Tauner
2023-07-28 16:26 ` Mike Burgess
2023-07-28 17:06 ` Richard Damon
2023-07-28 18:05 ` Grant Edwards
2023-07-28 18:27 ` panda.trooper
2023-07-28 20:23 ` Jon Beniston
2023-07-28 21:42 ` panda.trooper [this message]
2023-07-28 21:53 ` Jon Beniston
2023-07-29 12:47 ` Trampas Stern
2023-07-29 13:19 ` Stefan Tauner
2023-07-29 21:21 ` Grant Edwards
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='mbDd8IERY7M0G1lBn5FywuMKfPvSzWZhqLa1QfC7m5sX0T93-Ck-kM_OD2atJdTl8PMxOiRfuwo_JIspF53B4Fj4wqHz-qINH6bYBV-wzN8=@protonmail.com' \
--to=panda.trooper@protonmail.com \
--cc=jon@beniston.com \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).