Re: Macro calling kernel function



In article <1122596305.573850.178300@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
David <know_devig@xxxxxxxxxxx> wrote:
>I am using header file for driver so Can I define macro to call Kernel
>function ?

As phrased, NO.


>What are the generatl rules for defining macro.

They can be object-like (no parameters) or function-like
(with parameters.) In C89, the number of parameters for
a function-like macro must be constant; if I recall correctly, C99
has provision for variable number of arguments [I'm not sure on that.]

object-like macros are just substituted where-ever they are
found outside of quoted strings. *Whever* you have defined the
macro as will be dropped in -- it is, for example, perfectly
legal to

#define BEGIN {
#define END }

and then code

if (foo) BEGIN i++; END

function-like macros are substituted when they are found outside of
quoted strings in a function-like context. The actual parameters you
supplied are textually dropped in in place of the placeholders of the
macro definition. Again, it is not necessary that the definition expand
to a complete statement or complete syntactical grouping: like
object-like macros, function-like macros can be used to introduce new
syntactic sugar.

There are rules about re-scanning the text and re-subtituting, and
there are rules that prevent recursive macro expansion.

So... macros can be used to substitute in text, and the result will
have the same effect as if you had originally written the text at that
point (except as modified by the non-recursion rule.)

You thus cannot do anything with macros that you couldn't just write
yourself by hand.

Now, the reason that I said above that NO, you cannot define macros to
call kernel functions, is that macros cannot "call" -anything-:
they can just do textual substitutions. The substituted text
might happen to be such that after compilation and linking a
kernel function would be called at that point -- but only to
exactly the same extent that the context would have permitted
you to put in the C code for the kernel call manually. Macros
do not add any additional power to call kernel functions;
nor do they reduce that power: they merely provide alternative
ways of writing text that will expand to the same code.
--
Ceci, ce n'est pas une idée.
.



Relevant Pages

  • Re: Neatest way to get the end pointer?
    ... Macros like clamp, lerp, uniform, and so on are sufficiently function-like that it makes sense to use the same typography as functions. ... However Nintendo's N64 graphics pipeline macros, which had to take an arguement of the form ptr++ because they sometimes expanded to two or more pipeline comands, were made to look like function calls. ... So lower case for portable macros, mixed case for macros that depend on something other than the standard library, as with fucntions, caps for structure typedefs. ...
    (comp.lang.c)
  • Indian Hill, Re: Neatest way to get the end pointer?
    ... Isn't that what you say about *all* capitalized macros? ... function-like that it makes sense to use the same ... structure typedefs. ... I prefer Indian Hill style naming conventions. ...
    (comp.lang.c)
  • Re: Macro al posto di una funzione
    ... >be distinguished from real functions; ... >macros can evaluate their arguments more than once. ... The way to define function-like macros is ... CLC FAQ CLC readme: ...
    (comp.lang.c)
  • Re: Malcolms new book - Chapter 1 review
    ... convention that macros shall be uppercase. ... write all my macros in uppercase, function-like or otherwise. ...
    (comp.lang.c)
  • Help with function-like macros
    ... I'm personally not fond of function-like macros and wanted to turn these ... into static inline functions, but I'm having trouble doing so because the ... This seems to require that the signatures be ...
    (comp.lang.c)