[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] scripts/checkpatch.pl: fix false error ofexter
From: |
jiang.biao2 |
Subject: |
Re: [Qemu-devel] [PATCH] scripts/checkpatch.pl: fix false error ofexterns checking. |
Date: |
Wed, 11 Oct 2017 08:20:26 +0800 (CST) |
> On 10 October 2017 at 08:54, Jiang Biao <address@hidden> wrote:
> > When adding a function declaration in a .c file without extern
> >keywork decoration, checkpatch.pl will report *externs should be
> > avoided in .c files* false error. This patch fixes the bug.
>
> I don't think this is a bug. "extern int foo(void);" and
> "int foo(void);" have the same effect: they declare a function
> prototype that can be called from outside the file.
> We don't want to permit that in QEMU. Either:
> (1) the function is for use only within this file: the
> declaration should be "static int foo(void);"
> (2) the function is for use by other files too: the
> declaration should be in a header file, not a .c file,
> so the other files can use it
>
> Do you have an example of code where this warning is a problem?
Hi Peter,
I understand external functions should be put in header files. But there
is some rare exceptions, take the code segment in
tcg/mips/tcg-target.inc.c for example,
#if TCG_TARGET_REG_BITS == 32
# define LO_OFF (MIPS_BE * 4)
# define HI_OFF (4 - LO_OFF)
#else
/* To assert at compile-time that these values are never used
for TCG_TARGET_REG_BITS == 64. */
/* extern */ int link_error(void);
# define LO_OFF link_error()
# define HI_OFF link_error()
#endif
In this case, the external funciton is just used to assert at complie-time.
If I make a patch to delete the commented out extern before *int link_error()*,
the checkpatch.pl will complain the *externs should be avoided in .c files*
error.
The same usage can also be found in tcg/tcg-op.c,
/* Reduce the number of ifdefs below. This assumes that all uses of
TCGV_HIGH and TCGV_LOW are properly protected by a conditional that
the compiler can eliminate. */
#if TCG_TARGET_REG_BITS == 64
extern TCGv_i32 TCGV_LOW_link_error(TCGv_i64);
extern TCGv_i32 TCGV_HIGH_link_error(TCGv_i64);
#define TCGV_LOW TCGV_LOW_link_error
#define TCGV_HIGH TCGV_HIGH_link_error
#endif
I'm not sure if the checkpatch.pl should take these case into consideration. :)
Thanks.
Regards.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Qemu-devel] [PATCH] scripts/checkpatch.pl: fix false error ofexterns checking.,
jiang.biao2 <=