2002-09-20 17:08:13

by Jean Tourrilhes

[permalink] [raw]
Subject: Re: FW: 2.5.34: IR __FUNCTION__ breakage

On Fri, Sep 13, 2002 at 08:25:50AM +0200, Dag Brattli wrote:
> -----Original Message-----
> From: Thunder from the hill [mailto:[email protected]]
> Sent: 12. september 2002 22:17
> To: Bob_Tracy
> Cc: [email protected]; [email protected]
> Subject: Re: 2.5.34: IR __FUNCTION__ breakage
>
>
> Hi,
>
> On Thu, 12 Sep 2002, Bob_Tracy wrote:
> > define DERROR(dbg, args...) \
> > {if(DEBUG_##dbg){\
> > printk(KERN_INFO "irnet: %s(): ", __FUNCTION__);\
> > printk(KERN_INFO args);}}
> >
> > which strikes me as not quite what the author intended, although it
> > should work.
>
> Why not
>
> #define DERROR(dbg, fmt, args...) \
> do { if (DEBUG_##dbg) \
> printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION, args); \
> } while(0)
>
> ?
>
> Thunder

Try it, it won't work when there is zero args.

Jean


2002-09-20 17:21:26

by Thunder from the hill

[permalink] [raw]
Subject: Re: FW: 2.5.34: IR __FUNCTION__ breakage

Hi,

On Fri, 20 Sep 2002, Jean Tourrilhes wrote:
> > Why not
> >
> > #define DERROR(dbg, fmt, args...) \
> > do { if (DEBUG_##dbg) \
> > printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION, args); \
> > } while(0)
> >
> > ?
> >
> > Thunder
>
> Try it, it won't work when there is zero args.

It got corrected shortly afterwards. The non-typo version is:

#define DERROR(dbg, fmt, args...) \
do { if(DEBUG_##dbg) \
printk(KERN_INFO "irnet: %s(): " fmt, __FUNCTION__, ##args); \
} while(0)

Example:
#define DEBUG(fmt, args...) \
printf("%s(): " fmt, __FUNCTION__, ## args)

int main(void)
{
DEBUG("I am hungry.\n");

exit(0);
}

# gcc -Wall -Os -o moehre -s moehre.c
# ./moehre
main(): I am hungry.
#

Thunder
--
assert(typeof((fool)->next) == typeof(fool)); /* wrong */