Computer Programming
C Programming
The Difference Between

What are the differences between Macros and Functions in C Language?


Top Answer
User Avatar
Wiki User
2010-12-26 15:30:44
2010-12-26 15:30:44

Macros are essentially shorthand representations of arbitrary sections of the source code, which makes the source code succinct, while its (the macro template's) expansion replaces each of its presence prior to compilation. Whatever is there to do with Macros, it is done by the preprocessor, so that the source code is ready for compilation. Function is a calling routine, whence a large program is divided into separate portions, each portion doing a separate job, and proper calling of these portions in different places combines the works done by them into the required complete output. Thus functions have nothing to do with the preprocessing period, they are just compiled. To some extent function and macro is similar, for a macro can occasionally be invoked to perform a task that is generally entrusted to a function. But the similarity ends there.

The differences are:
  1. Macro consumes less time. When a function is called, arguments have to be passed to it, those arguments are accepted by corresponding dummy variables in the function, they are processed, and finally the function returns a value that is assigned to a variable (except for a void function). If a function is invoked a number of times, the times add up, and compilation is delayed. On the other hand, the macro expansion had already taken place and replaced each occurrence of the macro in the source code before the source code starts compiling, so it requires no additional time to execute.
  2. Function consumes less memory. While a function replete with macros may look succinct on surface, prior to compilation, all the macro-presences are replaced by their corresponding macro expansions, which consumes considerable memory. On the other hand, even if a function is invoked 100 times, it still occupies the same space. Hence function is more amenable to less memory requirements.

Related Questions

Macros can be used for a number of things. They can be used to create documents and other essential functions in a document easily. Macros are used for management and evaluation of spreadsheets.

Definitely functions, since they provide type safety. Many macros also generate unwanted behavior, because of the way they're expanded. In my opinion, just use inline functions, but if it seems appropriate to use macros, use them -- but do so, with caution.

Component Macros are built in functions used to control components such as an LCD display, EEPROM, switches, serial data, etc. Macros are user created functions that help make the program more modular. As far as I can tell, there are only those 2 types.

Advantage: Macros and Inline functions are efficient than calling a normal function. The times spend in calling the function is saved in case of macros and inline functions as these are included directly into the code. Disadvantage: Macros and inline functions increased the size of executable code. Difference in inline functions and macro 1) Macro is expanded by preprocessor and inline function are expanded by compiler. 2) Expressions passed as arguments to inline functions are evaluated only once while _expression passed as argument to inline functions are evaluated more than once. More over inline functions are used to overcome the overhead of function calls. Macros are used to maintain the readbility and easy maintainence of the code.

Word 2007 file extensions have been changed as noted below :Type FileWord 2007 document without macros .docxWord 2007 document with macros .docmWord 2007 Template without macros .dotxWord 2007 Template with macros .dotm

Macros are processed at preprocessing time where as constant variables are processed at complie time. Macros doesnot have any scope but constant variables has scope. Macros doesnot have the type checking where as constant variables have type checking.

Macros in Excel are used for tasks with high repetition. They are basically a way to automate certain functions and commands to greatly speed up the processing of large volumes of data.

Not much, except that the macros would be written to perform different tasks, because Word (word processor) and Excel (spreadsheet) have different functions. Both are written by the user to perform a specific task, but since each application handles most tasks differently, the macros would need to be designed for the tasks relevant to the specific application.

a wizard inserts fields and a macros is something like a hyperlink that when you click on it, it automatically takes you to another page!

Macros are not actually part of the C++ language; they are nothing more than a simple text-replacement system intended to simplify your coding. Macros do not adhere to C++ type safety and cannot be debugged because macros are preprocessed, prior to compilation. Your compiler can only see the preprocessed code, not the original source code, and therefore cannot debug macros because the macros no longer exist at that point. Inline functions are functions that can be debugged like any other function, but the compiler is able to eliminate the overhead of function calla by replacing those calls with inline expanded code. This is not unlike a macro, which is by definition inline expanded, but retains the built-in type safety and debugging capabilities of the C++ language itself. Typically, if you can use an inline function (or C++ is general) then that is always the preferred option. But if a macro can achieve more than can be achieved with C++ alone, or can otherwise simplify the equivalent C++ code, then use a macro. Just keep in mind that macros are not type-safe and cannot be debugged by the C++ compiler.

No, because Access will interpret a blank line as no further action and stop executing the macros.

The honest answer is: " is software and therefore can crash as any software." However, the more interesting question is does support macros? The answer is: Yes and No! does support its own macro language. However the standard edition (as of release 2.3) does not support Visual Basic Macros, as used in Microsoft Office. There are editions of OpenOffice, that support VBA macros.

# What are macros? what are its advantages and disadvantages? # What are macros? what are its advantages and disadvantages?

it contains the information used by character classification and character conversion macros

Macros are things that save time, ie instead of typing something more than once, you can use a macro, they do other things too but I am not into programming language, Visual Basic.

Macros and the Control Toolbox are completely different. Macros are for writing code to do automated tasks. The control toolbox has the controls you can put on your worksheet and forms, like buttons, drop down lists, text boxes, labels etc. You can assign a macro to a control, like having a button run a macro when it is clicked.

Macros are used to automate repetative tasks.

Yes, Excel supports macros. However, the free Office 2010 Starter Version does not support Macros.

You can open the Macros section and run macros from there. The quickest way to do that is press Alt - F8. You can also run macros by clicking on buttons or other objects that you have assigned them to.

Marketing functions for macros cannot be shifted or shared. They must all be processed by someone and none can be left out.

Macros isupper and islower from ctype.h will help you.

There can be many reasons why your macros are not working. Check security settings to ensure your version of Excel has macros enabled. Many times, the default installation disables the ability to use macros. Ensure you accept security certificates for the author of the macros.

You can do it by creating macros and then editing the macros. The macros or set of code can be applied to a button. It will depend on the version of Excel you have, but you can usually start creating macros or writing code through the Tools menu.

The use of Macros in Excel is that Macros is a set of instructions that are stored in the Excel program software. These instructions tell the program how to work properly.

Some word processor support macros, some does not.

Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.