473,666 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Plz clarify

Hello grp,
I have a doubt.
This is an example program I have written.
May not be useful but just wanted to understand.
short int hello(short int *i);
main()
{

short int i=2;
i = hello(&i);
i = hello(&i);
printf("%d",i);
}

short int hello(short int *i)
{
short int ret = *i;
return ret;
}

This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));

I get two errors expected l-value and
too few parameters..
Could anyone kindly explain me this.

Thaanx in advance.
Rgds,
Naren.

Nov 13 '05 #1
5 1691
On Wed, 23 Jul 2003 16:43:11 +0530, "Naren"
<na************ *@in.bosch.com> wrote:
short int hello(short int *i);
main()
{

short int i=2;
i = hello(&i);
i = hello(&i);
printf("%d",i);
}

short int hello(short int *i)
{
short int ret = *i;
return ret;
}

This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));


i = hello( (i = hello(&i), &i) );

Nick.
Nov 13 '05 #2
Naren wrote:
This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));


That's still two calls, even if you fex the errors.

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html
Nov 13 '05 #3

"Nick Austin" <ni**********@n ildram.co.uk> wrote in message
news:ek******** *************** *********@4ax.c om...
On Wed, 23 Jul 2003 16:43:11 +0530, "Naren"
<na************ *@in.bosch.com> wrote:
short int hello(short int *i);
main()
{

short int i=2;
i = hello(&i);
i = hello(&i);
printf("%d",i);
}

short int hello(short int *i)
{
short int ret = *i;
return ret;
}

This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));
i = hello( (i = hello(&i), &i) );


This is too good.but could you explain to me why mine went wrong?
Nick.

Nov 13 '05 #4

On Wed, 23 Jul 2003, Naren wrote:

"Nick Austin" <ni**********@n ildram.co.uk> wrote...
On Wed, 23 Jul 2003 16:43:11 +0530, "Naren" wrote...

main()
{

short int i=2;
i = hello(&i);
i = hello(&i);
printf("%d",i);
}

This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));


i = hello( (i = hello(&i), &i) );


This is too good.but could you explain to me why mine went wrong?


Yours tries to take the address of (i = hello(&i)), which is just
silly. (i = ...) is an expression, not an lvalue - it's like trying
to take the address of (i - 1), or (42). You just can't do it in
the C programming language, because the expression's value doesn't
necessarily have to "exist" anywhere that has an address to be
taken!

Nick's fix uses the "comma operator", which is *completely different*
from the commas used to separate function arguments. The comma operator
introduces a "sequence point" between the expression (i = hello(&i))
and the expression (&i), and returns the value of the second expression
(&i). That's the value that gets passed to 'hello' the second time.

Sequence points should be covered in the FAQ; search Google for
"comp.lang. c FAQ".

HTH,
-Arthur

Nov 13 '05 #5
In <bf**********@n s2.fe.internet. bosch.com> "Naren" <na************ *@in.bosch.com> writes:
This is an example program I have written.
May not be useful but just wanted to understand.
short int hello(short int *i);
main()
You may want to get into the habit of writing

int main()

which is required by C99 and even by certain C89 compilers operating in
"picky" mode.
{

short int i=2;
i = hello(&i);
i = hello(&i);
printf("%d",i);
You can't call printf without a proper declaration in scope. And it's
not wise to omit the newline character at the of the last line output
by your program.
}

short int hello(short int *i)
{
short int ret = *i;
return ret;
}

This works fine but I thought of replacing the two calls to hello

By one call

i = hello(&(i = hello(&i)));
To replace the two calls to hello by one call, simply drop one of your

i = hello(&i);

lines.
I get two errors expected l-value and
too few parameters..
Could anyone kindly explain me this.


i = hello(&i) is an expression that doesn't yield an lvalue, therefore
you can't take its address. There are simpler ways of calling hello()
twice in the same expression (although this is NOT what you said you want)

i = hello(&i), hello(&i);
or
i = (hello(&i), hello(&i));

Can you tell the difference between the two?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #6

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

Similar topics

1
1521
by: wil smiths | last post by:
in applet, "jFrame" cannot be added into applet right? ( I tried it out , cannot work; so i'm using jPanel) in applet/application , there are 3 way program start to flow :: 1. void init() 2. void start() 3. create function inside constructor of class.
3
1215
by: Guhanath | last post by:
Dear All, Is dot.Net Framework processor based and mainly targetted at Pentium machines??Will it work in AMD Processor especially AMD Athlon 64 Processors. -- Guhan
2
1333
by: grahamo | last post by:
Hi, I have something that I'd like to clarify here.... there are two issues. I have simple dummy class called base which (everything is inlined just for readability) defines these methods... friend base operator+ (const base& lhs, const base& rhs) { base tmp;
7
2522
by: hugo.elias | last post by:
Hi all, I hope nobody minds me posting this question to this group, but I couldn't find any group closer to the Subject. Can anyone clear up where you draw the lines when dividing up an application into Model, View and Controller parts? For example: I have some classes: class FlatWorld;
2
1529
by: bissatch | last post by:
Hi, I am one of the many that get fed up with browser sniffing and cross platform issues. Is ECMAscript a new independant cross platform specification that can do loads of nice things that JavaScript can do? If so, is it well supported? If someone could give me brief overview of this that would be great, thanks
1
2627
by: shumaker | last post by:
....please. I've found other posts that explain the Cascade options, but the Enforce relationships option still is foggy to me. As to "enforcing relationship for ... UPDATEs"(with cascade NOT checked), then I'm guessing that an update to that key field that would normally cascade will instead produce some sort of constraint violation error?
9
1342
by: javuchi | last post by:
I've been searching thru the library documentation, and this is the best code I can produce for this alogorithm: I'd like to return a dictionary which is a copy of 'another' dictionary whoes values are bigger than 'x' and has the keys 'keys': def my_search (another, keys, x): temp = another.fromkeys(keys) return dict( for k in temp.keys() for v in temp.values() if v>=x])
0
1045
by: Jean-Marc Blaise | last post by:
Hi, The following page http://www-1.ibm.com/support/docview.wss?uid=swg1IY63894 states at top of page that FP8a fixes the problem, and at the bottom "First fixed in v8.2 fp9". Could you clarify please ? Thanks a lot,
7
1967
ilikesuresh
by: ilikesuresh | last post by:
Hi i have written this program to find the file information using stat structure. When i try to display the mode it shows blank(nothing) where is the problem lies here.. clarify me... #include<stdio.h>
6
1253
ilikesuresh
by: ilikesuresh | last post by:
Hi i write a program in Pro *C to increase the salary of employees based on some constraints. Its works fine and if i execute the program in the first time the salaries would be increased depending on the constraints.But if i execute immediately the second time, the updated values have been treated as a old value and again the salaries are incremented.Is there any specific way to ensure this if the update happens continuously on the second...
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.