From owner-freebsd-current@FreeBSD.ORG Thu Dec 18 14:17:01 2014 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4E68E523 for ; Thu, 18 Dec 2014 14:17:01 +0000 (UTC) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 1404B1EFC for ; Thu, 18 Dec 2014 14:17:00 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 0C6627300A; Thu, 18 Dec 2014 15:21:15 +0100 (CET) Date: Thu, 18 Dec 2014 15:21:15 +0100 From: Luigi Rizzo To: current@freebsd.org Subject: wrapping a vararg C function (specifically, log() in the kernel) Message-ID: <20141218142115.GA17786@onelab2.iet.unipi.it> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Dec 2014 14:17:01 -0000 Hi, in the porting of some kernel code to FreeBSD, i need to remap one function with a variable number of arguments to the log() function from the freebsd kernel. Normally i would do #define WARN(x, args...) log(LOG_WARNING, args) but this does not work in my case because the function is called in (many) blocks where there is already a local variable with the same name bool log; which is used a ton of times. I was wondering if there is some C compiler magic i can use to do the remapping without going through a macro; I haven't found any direct one, though perhaps something like extern void (*freebsd_log)(int level, const char *fmt, ...); #define WARN(x, args...) freebsd_log(LOG_WARNING, args) followed somewhere in a safe place by freebsd_log = log; may do the job. Any other option ? cheers luigi