lkml.org 
[lkml]   [2001]   [Feb]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] a more efficient BUG() macro
Date
On Sun, 18 Feb 2001 12:33:35 +1100, 
Andrew Morton <andrewm@uow.edu.au> wrote:
>__BASE_FILE__ does this. It expands to the thing which you
>typed on the `gcc' command line.
>
>bix:/home/morton> ./a.out
>3 at a.c
>3 at a.c

But __LINE__ is wrong. Forget what I said about __C_FILE__ and
__C_LINE__, __C_LINE__ would not work for inline functions. Looks like
the best option is a combination of __BASE_FILE__ and function name.

a.h
#define BUG() \
printf("kernel BUG in func %s, file %s\n",__FUNCTION__,__BASE_FILE__);

static inline void hello(void)
{
BUG();
}

a.c
#include <stdio.h>
#include <a.h>

int main()
{
hello();
hello();
return 0;
}

# gcc -I`pwd` `pwd`/a.c -o a
# ./a
kernel BUG in func hello, file /home/kaos/a.c
kernel BUG in func hello, file /home/kaos/a.c

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:15    [W:0.249 / U:0.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site