bugAVR C Runtime Library - Bugs: bug #36571, stdint.h: INTn_C not standard...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #36571: stdint.h: INTn_C not standard compliant

Submitter:  Georg-Johann Lay <gjlayde>
Submitted:  Thu 31 May 2012 08:02:57 PM UTC
   
 
Category:  Header Severity:  3 - Normal
Priority:  9 - Immediate Item Group:  Header files
Status:  None Assigned to:  None
Percent Complete:  0% Open/Closed:  Open
Release:  1.8.0 Fixed Release:  None

Fri 16 Nov 2012 11:00:00 PM UTC, comment #1: 

Here is the output for -mint8:

$ echo | avr-gcc-4.7.2 -x c - -E -dM -mint8 | sort | grep 'INT.*_C'

#define __INT16_C(c) c ## L
#define __INT32_C(c) c ## LL
#define __INT8_C(c) c
#define __INTMAX_C(c) c ## LL
#define __UINT16_C(c) c ## UL
#define __UINT32_C(c) c ## ULL
#define __UINT8_C(c) c ## U
#define __UINTMAX_C(c) c ## ULL

Notice that simply adopting this does not work with macros.  Just consider:

#define F_CPU 0x80000

long f (void)
{
    return INT32_C (F_CPU);
}

which works with

#define INT32_C(c) __INT32_C(c)

but fails with

#define INT32_C(c) c ## L

Georg-Johann Lay <gjlayde>
Thu 31 May 2012 08:02:57 PM UTC, original submission:  

C99: 7.18.4 Macros for integer constants

writes in clause #3 on the INTn_C function-like macros:

Each invocation of one of these macros shall expand
to an integer constant expression suitable for use
in #if preprocessing directives.

However, stdint.h defines respective macros like so

#define INT8_C(value) ((int8_t) value)

which cannot be used in #if preprocessing directives.

FYI, avr-gcc built-in defines similar macros like so, provided -mint8 is off:

$ echo | avr-gcc -x c - -E -dM | sort | grep 'INT.*_C'

#define __INT8_C(c) c
#define __INT16_C(c) c
#define __INT32_C(c) c ## L
#define __INT64_C(c) c ## LL
#define __INTMAX_C(c) c ## LL
#define __UINT8_C(c) c
#define __UINT16_C(c) c ## U
#define __UINT32_C(c) c ## UL
#define __UINT64_C(c) c ## ULL
#define __UINTMAX_C(c) c ## ULL

With -mint8 on, it should be something around (no appropriate compiler handy at the moment)

#define __INT8_C(c) c
#define __INT16_C(c) c ## L
#define __INT32_C(c) c ## LL
#define __INTMAX_C(c) c ## LL
#define __UINT8_C(c) c ## U
#define __UINT16_C(c) c ## UL
#define __UINT32_C(c) c ## ULL
#define __UINTMAX_C(c) c ## ULL

So avr-libc could adopt these or just

#define INT8_C(c) __INT8_C(c)

which works since gcc 4.5, maybe also 4.4.



Georg-Johann Lay <gjlayde>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by arcanum (Updated the item)
  • -email is unavailable- added by gjlayde (Submitted the item)
  •  

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-11-16 arcanum Priority5 - Normal 9 - Immediate

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code