signed, unless this assumption is known to be safe. For example,
although @code{off_t} is always signed, @code{time_t} need not be.
-@item
-Prefer the Emacs-defined type @code{printmax_t} for representing
-values that might be any signed integer that can be printed,
-using a @code{printf}-family function.
-
@item
Prefer @code{intmax_t} for representing values that might be any
signed integer value.
+A @code{printf}-family function can print such a value
+via a format like @code{"%"PRIdMAX}.
@item
Prefer @code{bool}, @code{false} and @code{true} for booleans.
xd_extract_signed (object,
TYPE_MINIMUM (dbus_int64_t),
TYPE_MAXIMUM (dbus_int64_t));
- printmax_t pval = val;
- XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
+ intmax_t pval = val;
+ XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval);
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
return;
dbus_uint64_t val =
xd_extract_unsigned (object,
TYPE_MAXIMUM (dbus_uint64_t));
- uprintmax_t pval = val;
- XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval);
+ uintmax_t pval = val;
+ XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval);
if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object);
return;
case DBUS_TYPE_INT64:
{
dbus_int64_t val;
- printmax_t pval;
dbus_message_iter_get_basic (iter, &val);
- pval = val;
- XD_DEBUG_MESSAGE ("%c %"pMd, dtype, pval);
+ intmax_t pval = val;
+ XD_DEBUG_MESSAGE ("%c %"PRIdMAX, dtype, pval);
return INT_TO_INTEGER (val);
}
case DBUS_TYPE_UINT64:
{
dbus_uint64_t val;
- uprintmax_t pval;
dbus_message_iter_get_basic (iter, &val);
- pval = val;
- XD_DEBUG_MESSAGE ("%c %"pMu, dtype, pval);
+ uintmax_t pval = val;
+ XD_DEBUG_MESSAGE ("%c %"PRIuMAX, dtype, pval);
return INT_TO_INTEGER (val);
}
/* A tick that's incremented each time something is added to the
history. */
-static uprintmax_t history_tick;
+static uintmax_t history_tick;
\f
/* Add to the redisplay history how window W has been displayed.
MSG is a trace containing the information how W's glyph matrix
++history_idx;
snprintf (buf, sizeof redisplay_history[0].trace,
- "%"pMu": window %p (%s)%s\n%s",
+ "%"PRIuMAX": window %p (%s)%s\n%s",
history_tick++,
ptr,
((BUFFERP (w->contents)
buf = redisplay_history[history_idx].trace;
++history_idx;
- sprintf (buf, "%"pMu": update frame %p%s",
+ sprintf (buf, "%"PRIuMAX": update frame %p%s",
history_tick++,
ptr, paused_p ? " ***paused***" : "");
}
%<flags><width><precision><length>character
where flags is [+ -0], width is [0-9]+, precision is .[0-9]+, and length
- is empty or l or the value of the pD or pI or pMd (sans "d") macros.
+ is empty or l or the value of the pD or pI or PRIdMAX (sans "d") macros.
Also, %% in a format stands for a single % in the output. A % that
does not introduce a valid %-sequence causes undefined behavior.
the respective argument is to be treated as `long int' or `unsigned long
int'. Similarly, the value of the pD macro means to use ptrdiff_t,
the value of the pI macro means to use EMACS_INT or EMACS_UINT, the
- value of the pMd etc. macros means to use intmax_t or uintmax_t,
+ value of the PRIdMAX etc. macros means to use intmax_t or uintmax_t,
and the empty length modifier means `int' or `unsigned int'.
The width specifier supplies a lower limit for the length of the printed
enum {
pDlen = sizeof pD - 1,
pIlen = sizeof pI - 1,
- pMlen = sizeof pMd - 2
+ pMlen = sizeof PRIdMAX - 2
};
enum {
no_modifier, long_modifier, pD_modifier, pI_modifier, pM_modifier
length_modifier = pD_modifier;
if (mlen == pIlen && memcmp (fmt, pI, pIlen) == 0)
length_modifier = pI_modifier;
- if (mlen == pMlen && memcmp (fmt, pMd, pMlen) == 0)
+ if (mlen == pMlen && memcmp (fmt, PRIdMAX, pMlen) == 0)
length_modifier = pM_modifier;
}
error ("Format specifier doesn't match argument type");
else
{
- /* Length of pM (that is, of pMd without the trailing "d"). */
- enum { pMlen = sizeof pMd - 2 };
+ /* Length of PRIdMAX without the trailing "d". */
+ enum { pMlen = sizeof PRIdMAX - 2 };
/* Avoid undefined behavior in underlying sprintf. */
if (conversion == 'd' || conversion == 'i')
/* Create the copy of the conversion specification, with
any width and precision removed, with ".*" inserted,
with "L" possibly inserted for floating-point formats,
- and with pM inserted for integer formats.
+ and with PRIdMAX (sans "d") inserted for integer formats.
At most two flags F can be specified at once. */
char convspec[sizeof "%FF.*d" + max (sizeof "L" - 1, pMlen)];
char *f = convspec;
{
if (FIXNUMP (arg))
{
- printmax_t x = XFIXNUM (arg);
+ intmax_t x = XFIXNUM (arg);
sprintf_bytes = sprintf (p, convspec, prec, x);
}
else
}
else
{
- uprintmax_t x;
+ uintmax_t x;
bool negative;
if (FIXNUMP (arg))
{
else
{
double d = XFLOAT_DATA (arg);
- double uprintmax = TYPE_MAXIMUM (uprintmax_t);
- if (! (0 <= d && d < uprintmax + 1))
+ double uintmax = UINTMAX_MAX;
+ if (! (0 <= d && d < uintmax + 1))
xsignal1 (Qoverflow_error, arg);
x = d;
negative = false;
#if defined GNU_LINUX && defined HAVE_UNEXEC
/* The gap between BSS end and heap start as far as we can tell. */
-static uprintmax_t heap_bss_diff;
+static uintmax_t heap_bss_diff;
#endif
/* To run as a background daemon under Cocoa or Windows,
{
fprintf (stderr, "**************************************************\n");
fprintf (stderr, "Warning: Your system has a gap between BSS and the\n");
- fprintf (stderr, "heap (%"pMu" bytes). This usually means that exec-shield\n",
+ fprintf (stderr, ("heap (%"PRIuMAX" bytes). "
+ "This usually means that exec-shield\n"),
heap_bss_diff);
fprintf (stderr, "or something similar is in effect. The dump may\n");
fprintf (stderr, "fail because of this. See the section about\n");
lock_file_1 (char *lfname, bool force)
{
/* Call this first because it can GC. */
- printmax_t boot = get_boot_time ();
+ intmax_t boot = get_boot_time ();
Lisp_Object luser_name = Fuser_login_name (Qnil);
char const *user_name = STRINGP (luser_name) ? SSDATA (luser_name) : "";
Lisp_Object lhost_name = Fsystem_name ();
char const *host_name = STRINGP (lhost_name) ? SSDATA (lhost_name) : "";
char lock_info_str[MAX_LFINFO + 1];
- printmax_t pid = getpid ();
+ intmax_t pid = getpid ();
if (boot)
{
if (sizeof lock_info_str
<= snprintf (lock_info_str, sizeof lock_info_str,
- "%s@%s.%"pMd":%"pMd,
+ "%s@%s.%"PRIdMAX":%"PRIdMAX,
user_name, host_name, pid, boot))
return ENAMETOOLONG;
}
else if (sizeof lock_info_str
<= snprintf (lock_info_str, sizeof lock_info_str,
- "%s@%s.%"pMd,
+ "%s@%s.%"PRIdMAX,
user_name, host_name, pid))
return ENAMETOOLONG;
if (INTEGERP (val))
{
intmax_t v;
- if (! (integer_to_intmax (val, &v)
- && 0 < v && v <= TYPE_MAXIMUM (uprintmax_t)))
+ if (! (integer_to_intmax (val, &v) && 0 < v))
v = pixel_size;
if (v > 0)
{
- uprintmax_t u = v;
f[XLFD_PIXEL_INDEX] = p = font_size_index_buf;
- sprintf (p, "%"pMu"-*", u);
+ sprintf (p, "%"PRIdMAX"-*", v);
}
else
f[XLFD_PIXEL_INDEX] = "*-*";
\f
/* Construct a frame that refers to a terminal. */
-static printmax_t tty_frame_count;
+static intmax_t tty_frame_count;
struct frame *
make_initial_frame (void)
{
register struct frame *f;
Lisp_Object frame;
- char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
+ char name[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)];
if (!terminal->name)
error ("Terminal is not live, can't create new frames on it");
XSETFRAME (frame, f);
Vframe_list = Fcons (frame, Vframe_list);
- fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
+ fset_name (f, make_formatted_string (name, "F%"PRIdMAX, ++tty_frame_count));
SET_FRAME_VISIBLE (f, 1);
/* If NAME is nil, set the name to F<num>. */
if (NILP (name))
{
- char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
+ char namebuf[sizeof "F" + INT_STRLEN_BOUND (tty_frame_count)];
/* Check for no change needed in this very common case
before we do any consing. */
if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
return;
- name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
+ name = make_formatted_string (namebuf, "F%"PRIdMAX, ++tty_frame_count);
}
else
{
gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
{
Lisp_Object tem;
- uprintmax_t w;
+ uintmax_t w;
char buf[INT_BUFSIZE_BOUND (w)];
/* Represent negative positions (off the top or left screen edge)
warnings. */
w = (uintptr_t) FRAME_NATIVE_WINDOW (f);
store_in_alist (alistptr, Qwindow_id,
- make_formatted_string (buf, "%"pMu, w));
+ make_formatted_string (buf, "%"PRIuMAX, w));
#ifdef HAVE_X_WINDOWS
#ifdef USE_X_TOOLKIT
/* Tooltip frame may not have this widget. */
#endif
w = (uintptr_t) FRAME_OUTER_WINDOW (f);
store_in_alist (alistptr, Qouter_window_id,
- make_formatted_string (buf, "%"pMu, w));
+ make_formatted_string (buf, "%"PRIuMAX, w));
#endif
store_in_alist (alistptr, Qicon_name, f->icon_name);
store_in_alist (alistptr, Qvisibility,
SAFE_FREE ();
return list2 (output, actual_iv);
# else
- printmax_t print_gca = gca;
- error ("GnuTLS AEAD cipher %"pMd" is invalid or not found", print_gca);
+ intmax_t print_gca = gca;
+ error ("GnuTLS AEAD cipher %"PRIdMAX" is invalid or not found", print_gca);
# endif
}
static bool
gs_load (struct frame *f, struct image *img)
{
- uprintmax_t printnum1, printnum2;
- char buffer[sizeof " " + INT_STRLEN_BOUND (printmax_t)];
+ uintmax_t printnum1, printnum2;
+ char buffer[sizeof " " + 2 * INT_STRLEN_BOUND (intmax_t)];
Lisp_Object window_and_pixmap_id = Qnil, loader, pt_height, pt_width;
Lisp_Object frame;
double in_width, in_height;
printnum1 = FRAME_X_DRAWABLE (f);
printnum2 = img->pixmap;
window_and_pixmap_id
- = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2);
+ = make_formatted_string (buffer, "%"PRIuMAX" %"PRIuMAX,
+ printnum1, printnum2);
printnum1 = FRAME_FOREGROUND_PIXEL (f);
printnum2 = FRAME_BACKGROUND_PIXEL (f);
pixel_colors
- = make_formatted_string (buffer, "%"pMu" %"pMu, printnum1, printnum2);
+ = make_formatted_string (buffer, "%"PRIuMAX" %"PRIuMAX,
+ printnum1, printnum2);
XSETFRAME (frame, f);
loader = image_spec_value (img->spec, QCloader, NULL);
#endif
verify (BITS_WORD_MAX >> (BITS_PER_BITS_WORD - 1) == 1);
-/* printmax_t and uprintmax_t are types for printing large integers.
- These are the widest integers that are supported for printing.
- pMd etc. are conversions for printing them.
- On C99 hosts, there's no problem, as even the widest integers work.
- Fall back on EMACS_INT on pre-C99 hosts. */
-#ifdef PRIdMAX
-typedef intmax_t printmax_t;
-typedef uintmax_t uprintmax_t;
-# define pMd PRIdMAX
-# define pMu PRIuMAX
-# define pMx PRIxMAX
-#else
-typedef EMACS_INT printmax_t;
-typedef EMACS_UINT uprintmax_t;
-# define pMd pI"d"
-# define pMu pI"u"
-# define pMx pI"x"
-#endif
-
/* Use pD to format ptrdiff_t values, which suffice for indexes into
buffers and strings. Emacs never allocates objects larger than
PTRDIFF_MAX bytes, as they cause problems with pointer subtraction.
if (isnan (data))
{
union ieee754_double u = { .d = data };
- uprintmax_t hi = u.ieee_nan.mantissa0;
- return sprintf (buf, &"-%"pMu".0e+NaN"[!u.ieee_nan.negative],
+ uintmax_t hi = u.ieee_nan.mantissa0;
+ return sprintf (buf, &"-%"PRIuMAX".0e+NaN"[!u.ieee_nan.negative],
(hi << 31 << 1) + u.ieee_nan.mantissa1);
}
#endif
/* In theory this assignment could lose info on pre-C99
hosts, but in practice it doesn't. */
- uprintmax_t up = ui;
+ uintmax_t up = ui;
- int len = sprintf (buf, "at 0x%"pMx, up);
+ int len = sprintf (buf, "at 0x%"PRIxMAX, up);
strout (buf, len, len, printcharfun);
}
else
print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
{
char buf[max (sizeof "from..to..in " + 2 * INT_STRLEN_BOUND (EMACS_INT),
- max (sizeof " . #" + INT_STRLEN_BOUND (printmax_t),
+ max (sizeof " . #" + INT_STRLEN_BOUND (intmax_t),
max ((sizeof "at 0x"
- + (sizeof (uprintmax_t) * CHAR_BIT + 4 - 1) / 4),
+ + (sizeof (uintmax_t) * CHAR_BIT + 4 - 1) / 4),
40)))];
current_thread->stack_top = buf;
maybe_quit ();
/* Negative values of print-length are invalid in CL.
Treat them like nil, as CMUCL does. */
- printmax_t print_length = (FIXNATP (Vprint_length)
- ? XFIXNAT (Vprint_length)
- : TYPE_MAXIMUM (printmax_t));
+ intmax_t print_length = (FIXNATP (Vprint_length)
+ ? XFIXNAT (Vprint_length)
+ : INTMAX_MAX);
- printmax_t i = 0;
+ intmax_t i = 0;
while (CONSP (obj))
{
/* Detect circular list. */
/* Simple but incomplete way. */
if (i != 0 && EQ (obj, halftail))
{
- int len = sprintf (buf, " . #%"pMd, i / 2);
+ int len = sprintf (buf, " . #%"PRIdMAX, i >> 1);
strout (buf, len, len, printcharfun);
goto end_of_list;
}
/* If name is already in use, modify it until it is unused. */
Lisp_Object name1 = name;
- for (printmax_t i = 1; ; i++)
+ for (intmax_t i = 1; ; i++)
{
Lisp_Object tem = Fget_process (name1);
if (NILP (tem))
break;
- char const suffix_fmt[] = "<%"pMd">";
- char suffix[sizeof suffix_fmt + INT_STRLEN_BOUND (printmax_t)];
+ char const suffix_fmt[] = "<%"PRIdMAX">";
+ char suffix[sizeof suffix_fmt + INT_STRLEN_BOUND (i)];
AUTO_STRING_WITH_LEN (lsuffix, suffix, sprintf (suffix, suffix_fmt, i));
name1 = concat2 (name, lsuffix);
}
char *cmdline = NULL;
ptrdiff_t cmdline_size;
char c;
- printmax_t proc_id;
+ intmax_t proc_id;
int ppid, pgrp, sess, tty, tpgid, thcount;
uid_t uid;
gid_t gid;
CHECK_NUMBER (pid);
CONS_TO_INTEGER (pid, pid_t, proc_id);
- sprintf (procfn, "/proc/%"pMd, proc_id);
+ sprintf (procfn, "/proc/%"PRIdMAX, proc_id);
if (stat (procfn, &st) < 0)
return attrs;
struct psinfo pinfo;
int fd;
ssize_t nread;
- printmax_t proc_id;
+ intmax_t proc_id;
uid_t uid;
gid_t gid;
Lisp_Object attrs = Qnil;
CHECK_NUMBER (pid);
CONS_TO_INTEGER (pid, pid_t, proc_id);
- sprintf (procfn, "/proc/%"pMd, proc_id);
+ sprintf (procfn, "/proc/%"PRIdMAX, proc_id);
if (stat (procfn, &st) < 0)
return attrs;
static char const mon_name[][4] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
- printmax_t year_base = TM_YEAR_BASE;
+ intmax_t year_base = TM_YEAR_BASE;
char buf[sizeof "Mon Apr 30 12:49:17 " + INT_STRLEN_BOUND (int) + 1];
- int len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"pMd,
+ int len = sprintf (buf, "%s %s%3d %02d:%02d:%02d %"PRIdMAX,
wday_name[tm.tm_wday], mon_name[tm.tm_mon], tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
tm.tm_year + year_base);
&& TYPE_MAXIMUM (ElfW (Half)) <= PTRDIFF_MAX);
#ifdef UNEXELF_DEBUG
-# define DEBUG_LOG(expr) fprintf (stderr, #expr " 0x%jx\n", (uintmax_t) (expr))
+# define DEBUG_LOG(expr) fprintf (stderr, #expr " 0x%"PRIxMAX"\n", \
+ (uintmax_t) (expr))
#endif
/* Get the address of a particular section or program header entry,
if (nlflag)
{
ptrdiff_t this_bol, this_bol_byte, prev_bol, prev_bol_byte;
- printmax_t dups;
+ intmax_t dups;
/* Since we call del_range_both passing false for PREPARE,
we aren't prepared to run modification hooks (we could
if (dups > 1)
{
char dupstr[sizeof " [ times]"
- + INT_STRLEN_BOUND (printmax_t)];
+ + INT_STRLEN_BOUND (dups)];
/* If you change this format, don't forget to also
change message_log_check_duplicate. */
- int duplen = sprintf (dupstr, " [%"pMd" times]", dups);
+ int duplen = sprintf (dupstr, " [%"PRIdMAX" times]",
+ dups);
TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1);
insert_1_both (dupstr, duplen, duplen,
true, false, true);
#ifdef TRACE_SELECTION
#define TRACE0(fmt) \
- fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid ())
+ fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid ())
#define TRACE1(fmt, a0) \
- fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0)
+ fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0)
#define TRACE2(fmt, a0, a1) \
- fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1)
+ fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0, a1)
#define TRACE3(fmt, a0, a1, a2) \
- fprintf (stderr, "%"pMd": " fmt "\n", (printmax_t) getpid (), a0, a1, a2)
+ fprintf (stderr, "%"PRIdMAX": " fmt "\n", (intmax_t) getpid (), a0, a1, a2)
#else
#define TRACE0(fmt) (void) 0
#define TRACE1(fmt, a0) (void) 0