Macro calling kernel function

D

David

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
 
A

Artie Gold

David said:
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.]
 
S

Sensei

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.
 
W

Walter Roberson

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.
 
D

David

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
 
R

Randy Howard

David wrote
(in article
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.
 
K

Keith Thompson

David said:
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.)
 
C

CBFalconer

David said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Trouble calling a function with enum parameter 3
Please explain: #define MOVE 0x05 1
macro prototype 5
macro 41
macro chain 4
Endianness macros 48
C macro 3
Defining macro on the command-line vs in the source 3

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,911
Members
47,453
Latest member
MadelinePh

Latest Threads

Top