Re: reporting typedef errors automatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Nilsson

    Re: reporting typedef errors automatically

    Harald van D©¦k <true...@gmail. comwrote:
    ...
    When you define an array of length 0 the compiler
    will let you know you're doing something wrong.
    It is a constraint violation. Unfortunately, it's also
    not an uncommon extension to allow zero sized arrays,
    particularly at the end of a struct. So, I prefer
    ((need) ? 1 : -1) for compile time asserts.

    --
    Peter
  • Harald van =?UTF-8?b?RMSzaw==?=

    #2
    Re: reporting typedef errors automatically

    On Thu, 29 May 2008 14:57:57 -0700, Peter Nilsson wrote:
    Harald van Dijk <true...@gmail. comwrote:
    >...
    >When you define an array of length 0 the compiler will let you know
    >you're doing something wrong.
    >
    It is a constraint violation. Unfortunately, it's also not an uncommon
    extension to allow zero sized arrays, particularly at the end of a
    struct. So, I prefer ((need) ? 1 : -1) for compile time asserts.
    I agree, that's a better idea. However, I seem to recall reading that
    implementations exist that accept negative array length constants as well,
    and that it's even safer to use bit-field widths because of that.

    struct check {
    int member : (... ? 1 : -1);
    };

    As far as standard C is concerned, all are equivalent, as all violate a
    constraint if the check fails, but in practise, it's good to do whatever's
    reasonably possible to ensure the diagnostic is a fatal one.

    Comment

    Working...