473,506 Members | 16,201 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 1683
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**********@nildram.co.uk> wrote in message
news:ek********************************@4ax.com...
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**********@nildram.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**********@ns2.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
1509
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() ...
3
1204
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
1328
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... ...
7
2514
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...
2
1512
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...
1
2619
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...
9
1337
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...
0
1031
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...
7
1961
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... ...
6
1249
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...
0
7105
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...
0
7371
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...
1
7023
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...
0
5617
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,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.