473,396 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

what is call by name & how it is done

plz reply,
thanks in advance.
bye
Nov 14 '05 #1
2 13965
In article <11**************************@posting.google.com >
Sweety <sw************@yahoo.co.in> writes:
plz reply,
("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[i]);
/* 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[i]". In f(), the first operation
on "a[i]" (now named *p) is "set to 3", but then the second operation
is "increment i by 1". The third and last operation on "a[i]" 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[i]);
/* 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.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #2
Sweety wrote:

plz reply,


Oh very well.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
0
by: Gitesh | last post by:
..................... CALL FOR PAPERS ..................... The 2004 International Multiconference in Computer Science and Computer Engineering (18 Joint Int'l Conferences)...
1
by: bjam | last post by:
Hi, if I want to include a set of call template methods into my xsl file can I do that? Meaning I want to have the template method below of data_output in another file that I can use in several...
11
by: modemer | last post by:
If I define the following codes: void f(const MyClass & in) {cout << "f(const)\n";} void f(MyClass in) {cout<<"f()\n";} MyClass myclass; f(myclass); Compiler complain that it can't find...
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
4
by: Sweety | last post by:
plz reply, thanks in advance. bye
12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
6
by: Siegfried Heintze | last post by:
I have the following C# code in my web service: public static extern double add_(double X, double Y ); public double add (double X, double Y){ return add_(X, Y); }
4
by: iam247 | last post by:
Hi Can the following 2 things be done in asp.net? I do not need a lot of guidance on how to implement - just can it be done and any anticipated problems. 1. GENERATE PAGE ON THE FLY I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.