Macro calling kernel function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    #1

    Macro calling kernel function

    Hi,
    I am using header file for driver so Can I define macro to call Kernel
    function ?

    What are the generatl rules for defining macro.

    - David

  • Artie Gold

    #2
    Re: Macro calling kernel function

    David wrote:[color=blue]
    > Hi,
    > I am using header file for driver so Can I define macro to call Kernel
    > function ?[/color]

    A macro works by textual replacement. You can use a macro to do whatever
    you want; if the resultant code is correct, all is well.[color=blue]
    >
    > What are the generatl rules for defining macro.
    >[/color]
    There are none, other than `use sparingly'.

    HTH,
    --ag

    [The question you've asked indicates that you have no real understanding
    of how C works. *Please* get a good book. See http://www.accu.org for
    suggestions.]

    --
    Artie Gold -- Austin, Texas
    http://it-matters.blogspot.com (new post 12/5)
    http://www.cafepress.com/goldsays
    "If you have nothing to hide, you're not trying!"

    Comment

    • David

      #3
      Re: Macro calling kernel function

      Ok let me be more specific, I want to do this in header file. Is it
      still possbile?

      Comment

      • Sensei

        #4
        Re: Macro calling kernel function

        On 2005-07-28 19:44:22 -0500, "David" <know_devig@yah oo.co.in> said:
        [color=blue]
        > Ok let me be more specific, I want to do this in header file. Is it
        > still possbile?[/color]


        If you define in mynew.h:

        #define Ahgr printk

        You will have Ahgr substituted with printk everywhere your definition
        is still valid.

        --
        Sensei <senseiwa@tin.i t>

        cd /pub
        more beer

        Comment

        • Walter Roberson

          #5
          Re: Macro calling kernel function

          In article <1122596305.573 850.178300@f14g 2000cwb.googleg roups.com>,
          David <know_devig@yah oo.co.in> wrote:[color=blue]
          >I am using header file for driver so Can I define macro to call Kernel
          >function ?[/color]

          As phrased, NO.

          [color=blue]
          >What are the generatl rules for defining macro.[/color]

          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.

          Comment

          • David

            #6
            Re: Macro calling kernel function

            Thanks Walter.
            My problem is, I have C file and .h file in my driver
            If I define this macro in C file it compiles and links, no problem
            But I define same macro in .h file it throws compile error ..
            undeclared identifier for function name
            I tired including header file for the function but :(
            whats the reason behind that.

            - David

            Comment

            • Randy Howard

              #7
              Re: Macro calling kernel function

              David wrote
              (in article
              <1122601305.260 026.300550@g49g 2000cwa.googleg roups.com>):
              [color=blue]
              > Thanks Walter.
              > My problem is, I have C file and .h file in my driver
              > If I define this macro in C file it compiles and links, no problem
              > But I define same macro in .h file it throws compile error ..
              > undeclared identifier for function name
              > I tired including header file for the function but :(
              > whats the reason behind that.[/color]

              I'll hazard a guess. There are types declared in some other
              header(s) included in your .c file that you aren't including in
              your header file, causing it to fail.

              --
              Randy Howard (2reply remove FOOBAR)

              Comment

              • Keith Thompson

                #8
                Re: Macro calling kernel function

                "David" <know_devig@yah oo.co.in> writes:[color=blue]
                > My problem is, I have C file and .h file in my driver
                > If I define this macro in C file it compiles and links, no problem
                > But I define same macro in .h file it throws compile error ..
                > undeclared identifier for function name
                > I tired including header file for the function but :(
                > whats the reason behind that.[/color]

                We can't guess what the problem might be with the information you've
                given us. Show us some code and the *exact* error message you're
                getting, and we might be able to help.

                Whatever problem you're having with the macro definition, you would
                have the same problem if you removed the macro definition and manually
                expanded any references to the macro. There is no relationship
                between macros and kernel functions. It's almost like asking whether
                you can write a function call using emacs.

                (And there are no "kernel functions" in standard C.)

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • CBFalconer

                  #9
                  Re: Macro calling kernel function

                  David wrote:[color=blue]
                  >
                  > Ok let me be more specific, I want to do this in header file. Is
                  > it still possbile?[/color]

                  Usenet articles are delivered hither and thither, with no
                  guarantees of timing, retention, other articles, etc. Thus they
                  must always stand on their own. Yours doesn't. Specific about
                  what? Is what possible? etc. Always include adequate context, even
                  if you are using that thrice cursed google interface. In which
                  case you can lessen the curse by heeding the advice in my sig,
                  below.

                  Google is not usenet, only a very poor news server, and a very
                  useful archiver. Their server interface is so poor that they have
                  become a laughing stock, and have exceeded OE in foulness.

                  --
                  "If you want to post a followup via groups.google.c om, don't use
                  the broken "Reply" link at the bottom of the article. Click on
                  "show options" at the top of the article, then click on the
                  "Reply" at the bottom of the article headers." - Keith Thompson

                  Comment

                  Working...