("Plz"? I suppose this means "please go back and look at the subject,
even if whatever system you use to read news has now hidden it from
you." Luckily mine does not, so let me repeat it...)
what is call by name & how it is done?
In computer science / informatics, "call by name" usually refers
to a parameter-passing mechanism that does not exist in C (but did
in Algol). The mechanism simulates replacing all accesses to the
formal parameter in the callee with accesses to the actual parameter
in the caller, each time. A common example, not actual C code but
a sort of transliteration of an Algol call-by-name, might read:
static int i;
void f(int *p) {
*p = 3;
i += 1;
*p = 4;
}
void g(void) {
int a[2];
i = 0;
f(&a
);
/* after f() returns, we want a[0]==3 and a[1]==4 */
}
The reason this works in that other language (but not in C) is that
the call to f() says "operate on a". In f(), the first operation
on "a" (now named *p) is "set to 3", but then the second operation
is "increment i by 1". The third and last operation on "a" is
"set to 4". Since i has changed from 0 to 1, this is intended to
set a[1] to 4, rather than writing on a[0] again.
C programmers can simulate call-by-name fairly easily, by writing
macros instead of functions. Macros actually do textual substitution,
so we might replace the above (which does not work) with:
#define F(var) do { \
var = 3; \
i += 1; \
var = 4; \
} while (0) /* see the FAQ for the reason for the do-while loop */
void g(void) {
int a[2];
int i;
i = 0;
F(a);
/* the expansion of F() sets both a[0] and a[1] as desired */
}
Note that it was possible here to move the variable "i" into g(),
because F() is no longer an actual function.
In general "call-by-name"-like-mechanisms -- including the macro
expansion technique above -- lead to maintenance problems. This
is most likely why few languages have direct support for it.
You can simulate true call-by-name, rather than faking it with
macros, by writing C code that implements "thunks" (procedures that
return references to the variables in question -- in C, functions
that return pointers to the desired variables). This is generally
quite clumsy, and rarely useful. I have written articles in the
past showing how to write thunks in C; they are probably archived
in google.