macros_prog

Hye friends,

1)I had seen in many of the *.h files that following are specified

#if !defined(__ALLOC_H)
#define __ALLOC_H
---------
some codes go through

#endif

What is it's use? Why is it required ? Code can work well witout it also.
Moreover, what does allocate __ALLOC_H allocate in: #define __ALLOC_H
Will __ALLOC_H be equal to 1 ?

2) How to write an program "swap two numbers by using temp. variable" by using MACRO

Please answer me

Comments

  • Those macros only prevents your compiler from complaining about duplicate object definition errors when the same header file is included more than once in the same *.c, *.cpp or *.h file.

    : Moreover, what does allocate __ALLOC_H allocate in: #define __ALLOC_H
    : Will __ALLOC_H be equal to 1 ?

    [blue]All that does is define a symbol -- it is not defined to be anything, just defined to the compiler.[/blue]

    :
    : 2) How to write an program "swap two numbers by using temp. variable" by using MACRO
    :
    : Please answer me
    :
    [blue]If you know how to do that without using a macro, then just create a macro with the same code -- just put a backslash at the end of each line to indicate a continuation line[/blue]
    [code]
    #define SWAY(a,b)
    // rest of the code does here to swap
    // the values of and b.
    [/code]

  • : Those macros only prevents your compiler from complaining about duplicate object definition errors when the same header file is included more than once in the same *.c, *.cpp or *.h file.
    :
    : : Moreover, what does allocate __ALLOC_H allocate in: #define __ALLOC_H
    : : Will __ALLOC_H be equal to 1 ?
    :
    : [blue]All that does is define a symbol -- it is not defined to be anything, just defined to the compiler.[/blue]
    :
    : :
    : : 2) How to write an program "swap two numbers by using temp. variable" by using MACRO
    : :
    : : Please answer me
    : :
    : [blue]If you know how to do that without using a macro, then just create a macro with the same code -- just put a backslash at the end of each line to indicate a continuation line[/blue]
    : [code]
    : #define SWAY(a,b)
    : // rest of the code does here to swap
    : // the values of and b.

    you must use brackets too
    #define SWAY(a,b) {
    // rest of the code does here to swap
    // the values of and b. }

    [/code]

  • : : Those macros only prevents your compiler from complaining about duplicate object definition errors when the same header file is included more than once in the same *.c, *.cpp or *.h file.
    : :
    : : : Moreover, what does allocate __ALLOC_H allocate in: #define __ALLOC_H
    : : : Will __ALLOC_H be equal to 1 ?
    : :
    : : [blue]All that does is define a symbol -- it is not defined to be anything, just defined to the compiler.[/blue]
    : :
    : : :
    : : : 2) How to write an program "swap two numbers by using temp. variable" by using MACRO
    : : :
    : : : Please answer me
    : : :
    : : [blue]If you know how to do that without using a macro, then just create a macro with the same code -- just put a backslash at the end of each line to indicate a continuation line[/blue]
    : : [code]
    : : #define SWAY(a,b)
    : : // rest of the code does here to swap
    : : // the values of and b.
    :
    : you must use brackets too
    : #define SWAY(a,b) {
    : // rest of the code does here to swap
    : // the values of and b. }
    :
    : [/code]
    :
    : Thanks for the help

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories