473,748 Members | 3,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2079
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********@yah oo.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.i t>

cd /pub
more beer

Nov 15 '05 #4
In article <11************ **********@f14g 2000cwb.googleg roups.com>,
David <kn********@yah oo.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************ **********@g49g 2000cwa.googleg roups.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********@yah oo.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_Keit h) 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.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

Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
3254
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 clarification on what 'macro' means. A Lisp macro is a way of modifying code when that code is first defined. It can rearrange the structure of the code, and add and remove parts of it. Unlike C's #define macro language, Lisp macros understand the...
699
34065
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
5
1905
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", but I still would like to know because I am trying to encapsulate a third-party C-based callback-oriented gui toolkit inside C++ classes and I would like to try something. So say you have: long some_address = some_valid_address;
7
23555
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. Execution is faster. Where will it be stotred?(Is it in bss/stack/?) FUNCTION:
10
2432
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
2665
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 the database and i am calling that function in AccessMacro, and if i run that access macro in the backend, itsworking fine.But when i tried to call that access macro fromVB.NET code,i'm not getting any errors, but that macro is notworking. I'm calling...
37
8997
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 inline function ? thanks for any help in advance ...
1
3380
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 micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are: C:\Program Files\Coridium>cpp --version cpp (GCC) 3.2.3 (mingw special 20030504-1) Copyright...
9
1505
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 function) like,
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.