From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757552Ab2JBAsX (ORCPT ); Mon, 1 Oct 2012 20:48:23 -0400 Received: from mail-ia0-f174.google.com ([209.85.210.174]:65235 "EHLO mail-ia0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753972Ab2JBAsT (ORCPT ); Mon, 1 Oct 2012 20:48:19 -0400 MIME-Version: 1.0 In-Reply-To: <1348874411-28288-9-git-send-email-daniel.santos@pobox.com> References: <1348874411-28288-1-git-send-email-daniel.santos@pobox.com> <1348874411-28288-9-git-send-email-daniel.santos@pobox.com> Date: Mon, 1 Oct 2012 17:48:18 -0700 Message-ID: Subject: Re: [PATCH 8/10] bug.h: Make BUILD_BUG_ON generate compile-time error From: Michel Lespinasse To: Daniel Santos Cc: LKML , Andi Kleen , Andrea Arcangeli , Andrew Morton , Christopher Li , David Daney , David Howells , Joe Perches , Konstantin Khlebnikov , linux-sparse@vger.kernel.org, Paul Gortmaker , Pavel Pisa , Peter Zijlstra , Steven Rostedt Content-Type: text/plain; charset=ISO-8859-1 X-System-Of-Record: true Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 28, 2012 at 4:20 PM, Daniel Santos wrote: > Negative sized arrays wont create a compile-time error in some cases > starting with gcc 4.4 (e.g., inlined functions), but gcc 4.3 introduced > the error function attribute that will. This patch modifies > BUILD_BUG_ON to behave like BUILD_BUG already does, using the error > function attribute so that you don't have to build the entire kernel to > discover that you have a problem, and then enjoy trying to track it down > from a link-time error. Few other alternatives I've seen used in other projects (from memory, so I may have gotten the details wrong): 1) if (condition) { __asm__(".error \"Some error message\""); } 2) switch (0) { case 0: break; case !condition: break; } (fails to compile if !condition evaluates to 0) If you can get the first suggestion to work it'd be nice, as you could get some descriptive error message (you can add the line number there too). -- Michel "Walken" Lespinasse A program is never fully debugged until the last user dies.