answersLogoWhite

0


Best Answer

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.
User Avatar

Wiki User

โˆ™ 2010-12-26 15:30:44
This answer is:
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
User Avatar
Study guides
๐Ÿ““
See all Study Guides
โœ๏ธ
Create a Study Guide

Add your answer:

Earn +20 pts
Q: What are the differences between Macros and Functions in C Language?
Write your answer...
Submit
Related questions

Which is preferred to use in a program Macros or functions?

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.


What are macros used for?

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.


What types of macros are available in Flowcode?

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.


Advantages and disadvantages of using macro and inline functions?

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.


Which header files contain declaration for the files input and output functions and the macros defined and that are used with file input and output functions?

stdio.h


How marketing functions can be shifted and shared?

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


What is the difference between macros and constant variable?

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.


What are macros used for in Excel?

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.


What is the difference between macro and inline function in c plus plus?

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.


What is the difference between macros in Microsoft Word and Microsoft Excel?

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.


What is the difference between macros and wizard?

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!


Can you leave blank lines between macros in a macro group?

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


What are macros in Microsoft Word?

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.


Why you use ctype.h in c language?

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


What are macros what are its advantages and disadvantages?

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


What are the differences of macros and control toolbox?

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.


Can you do macros in Excel?

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


Why do you use macros?

Macros are used to automate repetative tasks.


How you run the macros into Microsoft Excel?

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.


What are the icons in Microsoft Word 2007 and their functions?

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


How do you get Macros to work on newer versions of Excel?

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.


Will openoffice crash with macros?

The honest answer is: "OpenOffice.org is software and therefore can crash as any software." However, the more interesting question is does OpenOffice.org support macros? The answer is: Yes and No! OpenOffice.org 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.


How marketing function can be shifted and shared?

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


In C programming language how to find weather given character is capital or small?

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


How do you run VB in Microsoft Excel?

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.