473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

Nov 15 '05 #1
8 2045
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
Ok let me be more specific, I want to do this in header file. Is it
still possbile?

Nov 15 '05 #3
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
10
by: Karim Thapa | last post by:
Why following macro does not work? #define removebrace(x) x void Foo(int a, int b, char *txt, int d, int e); main() {
1
by: Sen K via .NET 247 | last post by:
(Type your message here) Hi, Any help is appreciated. I have a situation wherein i need to compact access db after somebusiness logic through VB.NET.I've written a function in VBA tocompact...
37
by: junky_fellow | last post by:
hi guys, Can you please suggest that in what cases should a macro be preferred over inline function and viceversa ? Is there any case where using a macro will be more efficient as compared to...
1
by: todWulff | last post by:
Good day folks. Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based...
9
by: holysmoke | last post by:
Hi all, I have a function void actualfunction(unsigned int t, unsigned int lineno) { .... } I want that it is called only from a macro I wrote for it (I don't want to use a wrapper...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.