Re: [PATCH 8/9] pre-processor: add some pre-defined macros

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

 



On Mon, Nov 19, 2018 at 08:53:38PM +0000, Ramsay Jones wrote:
> 
> Signed-off-by: Ramsay Jones <ramsay@xxxxxxxxxxxxxxxxxxxx>
> ---
>  lib.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/lib.c b/lib.c
> index 23c3d27..08dc299 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -1248,6 +1262,53 @@ static void predefined_macros(void)
>  	predefined_type_size("LONG", "L", bits_in_long);
>  	predefined_type_size("LONG_LONG", "LL", bits_in_longlong);

I'm good with this but ...
  
> +	predefined_max("INT8", "", 8);
> +	predefined_type("INT8", "signed char");

We don't have a flag for it but in theory sparse supports
target where bits-per-char != 8. Some years ago someone
even used sparse on such a target.

> +	predefined_max("INT16", "", 16);
> +	predefined_type("INT16", "short int");
> +	predefined_max("INT32", "", 32);
> +	predefined_type("INT32", "int");

It would be nice to not assume sizeof(int) == 4
(but yes, I know, a lot of testcases assume it).

> +	predefined_umax("UINT8", "", 8);
> +	predefined_type("UINT8", "unsigned char");
> +	predefined_umax("UINT16", "", 16);
> +	predefined_type("UINT16", "short unsigned int");
> +	predefined_umax("UINT32", "U", 32);
> +	predefined_type("UINT32", "unsigned int");
> +
> +	if (bits_in_pointer == 64) {
> +		predefined_max("INT64", "L", 64);

This is not correct for LLP64 (-msize-llp64).

> +		predefined_type("INT64", "long int");
> +		predefined_max("INTMAX", "L", 64);
> +		predefined_type("INTMAX", "long int");
> +		predefined_max("INTPTR", "L", 64);
> +		predefined_type("INTPTR", "long int");
> +		predefined_max("PTRDIFF", "L", 64);
> +		predefined_type("PTRDIFF", "long int");
> +		predefined_umax("UINT64", "UL", 64);
> +		predefined_type("UINT64", "long unsigned int");
> +		predefined_umax("UINTMAX", "UL", 64);
> +		predefined_type("UINTMAX", "long unsigned int");
> +		predefined_umax("UINTPTR", "UL", 64);
> +		predefined_type("UINTPTR", "long unsigned int");
> +		predefined_umax("SIZE", "UL", 64);

For SIZE, best would be to keep everything together (and for the
suffix it's needed to check if (size_t_ctype == &ulong_ctype)
since, IIRC, some 32bit platforms use unsigned long for size_t).

In fact, it's a whole tricky affair. For example, on PPC32
UINT32_TYPE is defined as 'unsigned long int', PTRDIFF_TYPE is
defined as 'unsigned long int' on x86-x32. It's one of the
reasons I never added all those and left it to cgcc or undefined.

-- Luc



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux