From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shinya Kuribayashi Date: Thu, 25 Dec 2008 09:56:37 +0900 Subject: [U-Boot] [RFC][PATCH] Code Clean-up (weak functions) In-Reply-To: <3efb10970812241141x3e885bfakd74f631bc710b726@mail.gmail.com> References: <1229145986-9936-1-git-send-email-graeme.russ@gmail.com> <49518CF0.2040903@necel.com> <49526969.5000402@ruby.dti.ne.jp> <3efb10970812241141x3e885bfakd74f631bc710b726@mail.gmail.com> Message-ID: <4952DA45.3000805@necel.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Remy Bohmer wrote: > Create a default fallback routine that can be used if there is no > strong implementation: > ------------------------------------------------------------------------------------------- > __attribute__((weak)) unsigned long long printk_clock(void) > { > return sched_clock(); > } > ------------------------------------------------------------------------------------------- > and here is an example of the strong implementation (from the ARM architecture): > ------------------------------------------------------------------------------------------- > unsigned long long printk_clock(void) > { > return (unsigned long long)(jiffies - INITIAL_JIFFIES) * > (1000000000 / HZ); > } > ------------------------------------------------------------------------------------------- > > If the strong implementation is available, the weak is simply > discarded during linking, if the strong is omitted, the weak is used > as fallback. This is a clean, lean and mean example without > complex/superfluous aliases or checks for NULL pointers. > It should not get any harder than this... +1. I like this one, and U-Boot/MIPS _machine_restart() is implemented in the same manner. -- Shinya Kuribayashi NEC Electronics