Which one would you prefer - a macro or a function, C/C++ Programming

Assignment Help:

Which one would you prefer - a macro or a function?

Actually it depends on the purpose of program!

- In case of macros, corresponding code is inserted directly into your source code at the point where macro is called. No overhead is involved in using a macro. This makes Macros more efficient and faster than functions. Though, macros are generally small and can't handle large, complex coding constructs. So, if it's a complex situation that program wants to handle, functions are more suitable.

- Macros are expanded inline - this means that each time a macro occurs, code is replicated. So, code size in case of usage of macros would be larger in comparison to functions.

So, choice of using functions or macros actually depends of your requirement - speed vs. program size.

If your program includes small, repeated code sections, you must use Macros. If program requires, large number of unique code lines - you must prefer functions.

 


Related Discussions:- Which one would you prefer - a macro or a function

Probabilistic hough transform, Two kinds of line detection are implemented ...

Two kinds of line detection are implemented in OpenCV, the Hough Transform and the probabilistic Hough transform. Assume that there are n feature points in an image and that it tak

Explain object-oriented programming, Explain Object-oriented programming ...

Explain Object-oriented programming Object-oriented programming (OOP) attempts to meet these requirements, providing methods for managing enormous complexity, achieving reuse o

Boardcoloring, In this problem you are given a board in which some of the e...

In this problem you are given a board in which some of the elements are placed as shown in diagram below. Each element represents a color. Fill the other elements in the board, suc

Write down the class listnode, Question: (a) Write down the class 'Li...

Question: (a) Write down the class 'ListNode' to contain the following:- (i) variable data of type Object (ii) variable next of type ListNode (iii)

Write code to implement constructor, Study the following  class diagram, ad...

Study the following  class diagram, additional information  and answer  the  questions that follow: MovieTicket movieName: string TicketPrice: doub

Skilled programmer is required to build a standalone module, A skilled prog...

A skilled programmer is required to build a standalone module to extract, parse and store in database tables, word count data from web pages and RSS feeds. The module can take R

Write a program using a friend function, Using a Friend Using a friend ...

Using a Friend Using a friend function is quite easy. The following example explains a friend function to access members of two classes. class Bclass;

When do employ "const" reference arguments in function?, A: 1.      By u...

A: 1.      By using const protects you against programming errors which inadvertently alter data. 2.      By using const allows function to procedure const and non-const actu

Abstract array - c program, Abstract array - c program: AbstractArray:...

Abstract array - c program: AbstractArray::AbstractArray( int anUpper, int aLower, sizeType aDelta ) {     PRECONDITION( anUpper >= aLower );     lastElementIndex = a

Implement a algorithm to verify if the link list , Implement a Algorithm to...

Implement a Algorithm to verify if the link list is in Ascending order? A: template bool linklist::isAscending() const{ nodeptr ptr = head; while (ptr->_next)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd