[Top][All Lists]

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

Writing New Macros

From: Eric Lemings
Subject: Writing New Macros
Date: Mon, 9 Apr 2007 13:32:16 -0600


I could use some help/tips/pointers on writing new Autoconf macros
that do the following tasks:

1. An Autoconf macro that defines a preprocessor name with the expanded
value of an existing preprocessor name.  For example,

    FOO_REDEFINE_MACRO(FOO_CHAR_BIT, CHAR_BIT, [#include <limits.h>])

would define the name FOO_CHAR_BIT with the _expanded_ value of CHAR_BIT
from the <limits.h> header.  The purpose of this macro is to redefine a
name without any include dependencies.  So simply defining FOO_CHAR_BIT
as CHAR_BIT isn't good enough because FOO_CHAR_BIT would then require
including the <limits.h> header.  Similarly, simply defining
as the value of CHAR_BIT may not work either because CHAR_BIT itself may
be defined in terms of another preprocessor name.  The new name must be
defined as the preprocessed token(s) of the existing name -- an integral
constant in this case.

2. An Autoconf macro that checks whether a given type is a built-in
type or not.  This macro is similar to AC_CHECK_TYPE except that it
performs action-if-built-in only if the type is a built-in type and
action-if-not-built-in if the type is not defined or not a built-in
(Possibly the same as _AC_TYPE_CHECK_NEW without any includes at all.)

3. An Autoconf macro that defines a preprocessor name with the
fundamental type as an existing type definition.  This macro is similar
to the previous macro (and for similar reasons) except that it checks
for a typedef rather than a preprocessor name and defines the new name
with the _fundamental_ type of the existing typedef.  For example,


would define the preprocessor name FOO_INT8_T with the fundamental type
used to define int8_t in the default headers.  Note that the existing
type may be defined in terms of an intermediate type.  If int8_t is
defined in the default includes as

        #include <sys/types.h>
        typedef __sys_int8_t int8_t;

and the type __sys_int8_t is defined in <sys/types.h> as

        typedef char __sys_int8_t int8_t;

then FOO_INT8_T should be defined as

        #define FOO_INT8_T char

so that there are no include dependencies for FOO_INT8_T.

Any help with these is greatly appreciated.


reply via email to

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