[17479] in Kerberos_V5_Development

home help back first fref pref prev next nref lref last post

Re: Proposed platform assumption changes

daemon@ATHENA.MIT.EDU (Nico Williams)
Sun Jan 29 15:17:19 2012

MIME-Version: 1.0
In-Reply-To: <201201272355.q0RNt2pE007805@outgoing.mit.edu>
Date: Sun, 29 Jan 2012 14:17:14 -0600
Message-ID: <CAK3OfOhXFdURPqJRGF6d=t4CCnL1CwTDRFeKGFM+sLRuhHKmTw@mail.gmail.com>
From: Nico Williams <nico@cryptonector.com>
To: ghudson@mit.edu
Cc: krbdev@mit.edu
Content-Type: text/plain; charset="utf-8"
Errors-To: krbdev-bounces@mit.edu
Content-Transfer-Encoding: 8bit

On Fri, Jan 27, 2012 at 5:55 PM,  <ghudson@mit.edu> wrote:
> * Named structure initializers appear to be a favorite C99 feature;
>  we've had three separate cases in the past year of people submitting
>  code using them and having to ask for it to be changed.
>  Unfortunately, it's not supported in MSVC, and there's no pretty way
>  of wrapping them to make it work there.  We could consider changing
>  our Windows build to use mingw, but that would be a lot of work and
>  might present other issues.

I just tried the following macro for dealing with this.  It works, and
in particular cscope finds the initializers when I search by struct
field name -- a critical feature of C99 designated initializers, IMO.
I posted it as an answer on stackoverflow too (I was looking for this,
didn't find it).  This does require building with a C99 compiler for
checking correctness, but MIT krb5 already does that anyways, but a
variant that includes the struct name as a macro argument would allow
for a script to check correctness if that were important.

/*
 * Macro for C99 designated initializer -> C89/90 non-designated initializer
 *
 * Tested.  Works with MSVC if you undefine
HAVE_DESIGNATED_INITIALIZERS.  Cscope also
 * groks this.
 *
 * ("SFINIT" == struct field init, but really, it can be used for
array initializers too.)
 */

#ifdef HAVE_DESIGNATED_INITIALIZERS
#define SFINIT(f, v) f = v
#else
#define SFINIT(f, v) v
#endif

struct t {
    char f1;
    int f2;
    double f3;
};

struct t t = {
    SFINIT(.f1, 'a'),
    SFINIT(.f2, 42),
    SFINIT(.f3, 8.13)
};

Cheers,

Nico
--

_______________________________________________
krbdev mailing list             krbdev@mit.edu
https://mailman.mit.edu/mailman/listinfo/krbdev


home help back first fref pref prev next nref lref last post