[Top][All Lists]

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

[RFC,PATCH] C99 format specifiers for fixed-length integer types

From: Javier Martín
Subject: [RFC,PATCH] C99 format specifiers for fixed-length integer types
Date: Wed, 22 Jul 2009 21:10:49 +0200

This patch modifies the global types.h header to define a number of
macros used for the formatted output of fixed-length integers like
grub_uint64_t. Currently we use the traditional "%llu" format
specifiers, adding casts as required to assuage the loud GCC.

However, casts to shut the compiler up are generally a bad idea, and the
fact that this kind of output occurs mostly in debug code (printing an
inode number, for example) which is dispersed about the GRUB codebase
makes it very likely that the eventual breakage of one of these
assumptions will result in either a stream of warnings/errors or, given
that we are using casts to shut the compiler up, runtime weirdness.

Using these C99-like format specifiers will allow us to have the
relevant assumptions centralized in a single file, namely
<grub/types.h>. Thus, if and when one is broken - for example, when
sizeof(void*)!=sizeof(long), as it happens in mingw64 - the fix will be
way simpler to develop and deploy.

For example, using a fictional MyFS:

typedef struct {
    grub_uint64_t ino_num;
    grub_uint16_t perm_flags;
} myfs_ino_t;
myfs_ino_t *cur = ...

The patch will turn something like this:

    grub_dprintf("myfs", "Inode number %llu has permissions %03o",
                 (unsigned long) grub_be_to_cpu64(cur->ino_num),

Into this:

    grub_dprintf("myfs", "Inode number %"GRUB_PRI64u" has permissions "
                 "%03"GRUB_PRI16o, grub_be_to_cpu64(cur->ino_num),

-- Lazy, Oblivious, Recurrent Disaster -- Habbit

Attachment: prifmtspecs.patch
Description: Text Data

Attachment: signature.asc
Description: Esto es una parte de mensaje firmado digitalmente

reply via email to

[Prev in Thread] Current Thread [Next in Thread]