macro

Can i define a macro for a function of 10 LOC.

yes you can,

but i dont think there could be any such necessity for the same,

in case of function definition it is going to be one time and why do u need to have a macro for that,

macros are meant for substitution where u need to have many.

# include <stdio.h>

void fun();

# define ab void fun() { printf("fun\n"); }

int main()
{
   (void) fun();
   return 0;
}

ab

hope this helps, or could u please post your code ?

thanks matrixmadan.

  actually we want to overcome the time that is lost , a function

takes while visiting the stack twice.

i am afraid I didnt get your point exactly,

did u mean, popping and pushing function address and re-iterating program counter in stack trace ?

if that is so, then having a macro will not have any effect on the above,
as macro substitution would take place at the pre-compilation stage itself,

then goes compilation, linking, executing.
No way the time counters represented above would have an effect

If I had understood wrongly, please get me the correct point.

Thanks.

actually,
instead of calling a function we want a macro to do the job.
i.e can we have a function in the form of a macro.
e.g

#define fun(args....)
/*code for macro */
/*about 10 loc */
main()
{
....
....
....
fun(....);
....
}

then in such case,

make use of inline functions they get expanded in pre-compilation itself
similiar to macros.

But make sure that the function quoted as inline should not be a heavy-loaded which would drastically bring down the performance of the program.

i am afraid ,how will u use inline in C.
i think inline is available only in C++

yes,

inline functions only with c++

to go with c - only option to go with - macros.

Macros have been used to simulate inline functions from the very beginning of C. From the getc man page:

    The getc(3) function acts essentially identically to fgetc(3), but is a
    macro that expands in-line.

    The getchar(3) function is equivalent to:

    getc(stdin)

And many other "functions" included in the std i/o library are really macros. Take a peek at stdio.h.

you write a multi line macro as follows

#define func(arg) /
arg = arg + 1

the idea is to use the / to go on adding the next line for a macro.
I suppose that is what you were basically asking for.