can somebody explain me what is macro in programming
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
my language is c
can u tell me why would someone use macros in c for substiuate a variable with a value
One reason is to make the program run faster. When you have a function running, there's quite a lot of overhead. The function's variables have to be loaded onto the stack when the function is called. Then they have to be unloaded again when the function exits.
For a big, multi-line function, that overhead is acceptable. For a one-line function it wouldn't be, so you use a macro instead. Macros are created with #DEFINE (like named constants), so they are handled by the C preprocessor. Basically it's just a global edit; the macro call is replaced throughout by the line of code that it represents. Result: when the program runs, nothing has to be called, but you still have the convenience of typing in a name with some arguments rather than a line of complex code.
I'm sorry, but I do not really understand.
At first you need to specify the language you use. (I assume now it is C or C++). But in C, C++ all the macros are used in the same way. So probably would be better to give us more details or show some examples what do you mean.
Can somebody show me an exams about how to write macros that are used for conditional compiling like Unix
I wanna learn writing them to implement the. Further in my software
Ps : must be macros that used for conditional compiling
This is the fourth thread that you have opened about macro programming in the past few weeks. Macros for conditional compilation is not a significantly unique use case to begin a new thread without having shown that you have learned from the others, so I am merging this post into your most recent thread on the subject.
Please do not continue this behavior in the future, and again, please review the Site FAQ to which you have been previously referred for acceptable use of this forum.
I don't see much about C and C++ and nothing on the lines I am thinking of so here goes my maybe first answer to another question.
In C and C++ you can start a line with:
Code:
#define THIS THAT
and every time the compiler files THIS it replaces it with THAT. The THAT part can be quite lengthy and can have variables such that you have a macro with arguments. That topic is broad and deep and I stop here.
However, I do wish to note: The Joint Strike Fighter (JSF) program writes code for aircraft in C++ and has published their programming guidelines. Its easy to find with a search. Those guidelines declare that macros are not allowed. They can make the code extremely difficult to understand. You may have to force the compiler to save the preprocessor output so you can see what those macros have done to your code.
So,..., if you are at the point where you need to ask about macros, then the best advice is: Don't use them.
Part 2
In Microsoft Excel, Word, Access, and others, you can write VBA (Visual Basic for Application) code to do things. There is specialized grammar/syntax for the various Office applications. Such code is frequently, sometime invariably, called a macro. It is not, but it is called that anyway. If you want to go further this will be enough to get you started.
Last edited by bkelly; 11-27-2018 at 05:18 PM.
Reason: typo
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.