2010/1/5 Greg KH <greg@xxxxxxxxx>: > On Mon, Jan 04, 2010 at 03:32:07PM -0800, Bruce Blinn wrote: >> > -----Original Message----- >> > From: kernelnewbies-bounce@xxxxxxxxxxxx >> > [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Greg KH >> > Sent: Sunday, January 03, 2010 1:27 PM >> > To: Shawn >> > Cc: kernelnewbies@xxxxxxxxxxxx >> > Subject: Re: question about __v annotation >> > >> > >> > On Sat, Jan 02, 2010 at 09:10:08PM +0800, Shawn wrote: >> > > hello guys, >> > > I got a newbie confused when I was looking into the source code of >> > > s3c2440's RTC driver.I dont know what is __v excatly >> > means.anyone can >> > > tell?thanks anyway! >> > > >> > > #define readb(c) ({ __u8 __v = __raw_readb(__mem_pci(c)); __v; }) >> > >> > __v is an variable that the macro creates and then returns >> > the value of. >> > >> > Don't code like this, it's horrible :) >> > >> >> Could you be more specific with what you find wrong with this. The reason I >> ask is there is code like this all over the kernel. > > Like what specifically? > > Wrapping up a function call in a macro just because someone doesn't want > to type the whole thing out? That's the horrible thing. > > Returning a temporary variable isn't a big deal, but an inline function > is better to use as you will get the proper type safety. > i only can think about the reason why not use the inline is that it is support by C99 but not support by C89 ANSI C. Also i get the good reasons why use macro is "bad" in the WIKI. http://en.wikipedia.org/wiki/Inline_function " Use of true inline functions, as are available in C99, provides several benefits over this approach: Macro invocations do not perform type checking, or even check that arguments are well-formed, whereas function calls usually do. In C, a macro cannot use the return keyword with the same meaning as a function would do (it would make the function that asked the expansion terminate, rather than the macro). In other words, you cannot make the macro return something which is not the result of the last expression invoked inside it. Since C macros use mere textual substitution, this may result in unintended side-effects and inefficiency due to re-evaluation of arguments and order of operations. Compiler errors within macros are often difficult to understand, because they refer to the expanded code, rather than the code the programmer typed. Many constructs are awkward or impossible to express using macros, or use a significantly different syntax. In-line functions use the same syntax as ordinary functions, and can be inlined and un-inlined at will with ease. Debugging information for inlined code is usually more helpful than that of macro-expanded code. Many compilers can also inline expand some recursive functions; recursive macros are typically illegal. " > thanks, > > greg k-h > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- Best Regards Lin -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ