All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shailabh Nagar <nagar@watson.ibm.com>
To: balbir@in.ibm.com
Cc: Jay Lan <jlan@sgi.com>, Andrew Morton <akpm@osdl.org>,
	lkml <linux-kernel@vger.kernel.org>, Jes Sorensen <jes@sgi.com>,
	Chris Sturtivant <csturtiv@sgi.com>, Tony Ernst <tee@sgi.com>
Subject: Re: [patch 1/3] add basic accounting fields to taskstats
Date: Wed, 02 Aug 2006 13:37:46 -0400	[thread overview]
Message-ID: <44D0E2EA.6030301@watson.ibm.com> (raw)
In-Reply-To: <44D0DE13.7090205@in.ibm.com>

Balbir Singh wrote:

> 
> I am not sure if there is a version of BUG_ON() for compile time
> asserts. Basically, if we have an infrastructure of the form
> 
> /*
>  * From C/C++ users journal November 2004
>  */
> #define STATIC_BUG_ON(e)     \
>     switch (0) {        \
>     case  0:        \
>     case (e):        \
>         ;        \
>     }
> 
> Then the STATIC_BUG_ON() can catch as shown below.
> 
> #define TASK_COMM_LEN     16
> #define T_COMM_LEN    20
> 
> int
> main(void)
> {
>     STATIC_BUG_ON(TASK_COMM_LEN == T_COMM_LEN);
> }
> 
> STATIC_BUG_ON gives the following warning
> 
> bug_on_c.c: In function `main':
> bug_on_c.c:19: duplicate case value
> bug_on_c.c:19: previously used here
> 
> but with T_COMM_LEN set to 16
> 
> It compiles without any errors, the code generated also
> looks like it has no overhead
> 
> int
> main(void)
> {
>  8048310:       55                      push   %ebp
>  8048311:       89 e5                   mov    %esp,%ebp
>  8048313:       83 ec 08                sub    $0x8,%esp
>  8048316:       83 e4 f0                and    $0xfffffff0,%esp
>         STATIC_BUG_ON(TASK_COMM_LEN == T_COMM_LEN);
> }
>  8048319:       c9                      leave
>  804831a:       c3                      ret
>  804831b:       90                      nop
> 
> 
> Assuming such infrastructure is available, you could then
> do
> 
> #ifdef __KERNEL__
> #include <linux/sched.h>
> #define TS_COMM_LEN    16
> STATIC_BUG_ON (TS_COMM_LEN == TASK_COMM_LEN);
> #endif
> 
> Comments?
> 

Neat trick !
Perhaps STATIC_WARNING is a more appropriate name but
something like this for general use may be good.


--Shailabh

  reply	other threads:[~2006-08-02 17:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-31 19:20 [patch 1/3] add basic accounting fields to taskstats Jay Lan
2006-07-31 20:23 ` Shailabh Nagar
2006-07-31 21:50   ` Jay Lan
2006-08-01 14:24 ` Balbir Singh
2006-08-01 21:51   ` Jay Lan
2006-08-02 15:31     ` Shailabh Nagar
2006-08-02 17:17       ` Balbir Singh
2006-08-02 17:37         ` Shailabh Nagar [this message]
2006-08-02 21:09         ` Andrew Morton
2006-08-02 23:47           ` Jay Lan
2006-08-03  3:02           ` Balbir Singh
2006-08-07 21:23     ` Jay Lan
2006-08-08  5:22       ` Balbir Singh
2006-08-08 16:40         ` Jay Lan
  -- strict thread matches above, loose matches on Subject: below --
2006-08-08 14:57 Al Boldi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44D0E2EA.6030301@watson.ibm.com \
    --to=nagar@watson.ibm.com \
    --cc=akpm@osdl.org \
    --cc=balbir@in.ibm.com \
    --cc=csturtiv@sgi.com \
    --cc=jes@sgi.com \
    --cc=jlan@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tee@sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.