comp.lang.ada
 help / color / mirror / Atom feed
From: Duncan Sands <baldrick@free.fr>
To: Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de>,
	comp.lang.ada@ada-france.org
Subject: Re: C's trikery semantic opens up backdoor in new Linux kernel
Date: Fri, 14 Nov 2003 16:38:08 +0100
Date: 2003-11-14T16:38:08+01:00	[thread overview]
Message-ID: <mailman.7.1068824230.3110.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <bp2r4m$mi8$1@a1-hrz.uni-duisburg.de>

On Friday 14 November 2003 16:08, Georg Bauhaus wrote:
> Vinzent 'Gadget' Hoefler <ada.rocks@jlfencey.com> wrote:
> : Of course. But think about it: Isn't it a funny thing that you can do
> : a thing efficient enough in Ada just to prevent a problem in C, which
> : OTOH you even wouldn't have at all if you'd use Ada in the first
> : place?
> :
> : What's the definition for this sort of stuff called?
>
> Windows 3.1?  Will they still laugh at me now, Duncan? :-)

Hey - I liked windows 3.1!  After all, it made my OS/2 system look so spiffy. :)

By the way, here is an extract from the linux kernel documentation:


-------------------

2) #ifdefs are ugly

Code cluttered with ifdefs is difficult to read and maintain.  Don't do
it.  Instead, put your ifdefs in a header, and conditionally define
'static inline' functions, or macros, which are used in the code.
Let the compiler optimize away the "no-op" case.

Simple example, of poor code:

	dev = init_etherdev (NULL, 0);
	if (!dev)
		return -ENODEV;
	#ifdef CONFIG_NET_FUNKINESS
	init_funky_net(dev);
	#endif

Cleaned-up example:

(in header)
	#ifndef CONFIG_NET_FUNKINESS
	static inline void init_funky_net (struct net_device *d) {}
	#endif

(in the code itself)
	dev = init_etherdev (NULL, 0);
	if (!dev)
		return -ENODEV;
	init_funky_net(dev);



3) 'static inline' is better than a macro

Static inline functions are greatly preferred over macros.
They provide type safety, have no length limitations, no formatting
limitations, and under gcc they are as cheap as macros.

Macros should only be used for cases where a static inline is clearly
suboptimal [there a few, isolated cases of this in fast paths],
or where it is impossible to use a static inline function [such as
string-izing].

'static inline' is preferred over 'static __inline__', 'extern inline',
and 'extern __inline__'.



  reply	other threads:[~2003-11-14 15:38 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-12  3:17 C's trikery semantic opens up backdoor in new Linux kernel Adrian Hoe
2003-11-12  4:26 ` Stephane Richard
2003-11-12  5:13   ` J Cusick
2003-11-12  7:18     ` Vinzent 'Gadget' Hoefler
2003-11-12  7:50       ` Duncan Sands
2003-11-12 12:08         ` Vinzent 'Gadget' Hoefler
2003-11-12 13:38           ` Duncan Sands
2003-11-12 14:09             ` Vinzent 'Gadget' Hoefler
2003-11-13 21:04               ` Craig Carey
2003-11-14  6:45                 ` Freejack
2003-11-14  8:33                 ` Erlo Haugen
2003-11-14  9:44                   ` Vinzent 'Gadget' Hoefler
2003-11-14 10:16                     ` Dmitry A. Kazakov
2003-11-25 10:06                       ` Craig Carey
2003-11-25 11:20                         ` Dmitry A. Kazakov
2003-11-14 15:31                 ` Robert I. Eachus
2003-11-14 13:12               ` Georg Bauhaus
2003-11-14 13:31                 ` Duncan Sands
2003-11-14 14:56                 ` Vinzent 'Gadget' Hoefler
2003-11-14 15:08                   ` Georg Bauhaus
2003-11-14 15:38                     ` Duncan Sands [this message]
2003-11-14 17:57                       ` Georg Bauhaus
2003-11-14 15:47               ` Robert I. Eachus
2003-11-14 16:38                 ` Vinzent 'Gadget' Hoefler
2003-11-19  4:13             ` Dave Thompson
2003-11-21 15:34               ` Martin Krischik
2003-11-23  2:20                 ` Hyman Rosen
2003-11-27  4:22                 ` Dave Thompson
2003-11-28 14:01                   ` Hyman Rosen
2003-11-12 17:37       ` tmoran
2003-11-12 18:03       ` Warren W. Gay VE3WWG
2003-11-12  8:51     ` Adrian Hoe
2003-11-12 12:32       ` Preben Randhol
2003-11-13  5:50         ` Chad R. Meiners
2003-11-12 22:59       ` Wes Groleau
2003-11-14  3:31         ` Adrian Hoe
2003-11-14 11:00           ` Dmytry Lavrov
2003-11-15  5:00             ` Adrian Hoe
2003-11-15  5:02             ` Adrian Hoe
2003-11-16 11:29               ` Dmytry Lavrov
2003-11-17 17:07                 ` Warren W. Gay VE3WWG
2003-11-16 11:35             ` Dmytry Lavrov
2003-11-15 19:30           ` Wes Groleau
2003-11-12  8:52   ` Adrian Hoe
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox