By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,870 Members | 2,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,870 IT Pros & Developers. It's quick & easy.

Macro calling kernel function

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
David wrote:
Hi,
I am using header file for driver so Can I define macro to call Kernel
function ?
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.
What are the generatl rules for defining macro.

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!"
Nov 15 '05 #2

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

Nov 15 '05 #3

P: n/a
On 2005-07-28 19:44:22 -0500, "David" <kn********@yahoo.co.in> said:
Ok let me be more specific, I want to do this in header file. Is it
still possbile?

If you define in mynew.h:

#define Ahgr printk

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

--
Sensei <se******@tin.it>

cd /pub
more beer

Nov 15 '05 #4

P: n/a
In article <11**********************@f14g2000cwb.googlegroups .com>,
David <kn********@yahoo.co.in> 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.
Nov 15 '05 #5

P: n/a
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

Nov 15 '05 #6

P: n/a
David wrote
(in article
<11**********************@g49g2000cwa.googlegroups .com>):
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.


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)

Nov 15 '05 #7

P: n/a
"David" <kn********@yahoo.co.in> writes:
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.


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_Keith) ks***@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.
Nov 15 '05 #8

P: n/a
David wrote:

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


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.com, 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

Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.