473,703 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function order.

mdh
May I ask the group the following: (Again, alas , from K&R)

This is part of a function:

while ( ( array1[i++] = array2 [k++]) != '\0' ); /* etc etc */
Is this the order that this is evaluated?

-> array2[k] is assigned to array1[i] ....???? the reason being it is
within parenthesis ???

-> array1[i] is tested for non-equality to '\0'

-> if TRUE array1[i] is incremented to array1[i+1]

-> if TRUE array2[k] is incremented to to array2[k+1]

-> if FALSE exit loop and neither k nor i is incrmented.

Thank you for your indulgence....a nd also thank you all for making this
so pleasurable.

May 2 '06 #1
16 2445
mdh wrote:
May I ask the group the following: (Again, alas , from K&R)

This is part of a function:

while ( ( array1[i++] = array2 [k++]) != '\0' ); /* etc etc */
Is this the order that this is evaluated?

-> array2[k] is assigned to array1[i] ....???? the reason being it is
within parenthesis ???
Correct.

Also both i and k are incremented.

The expression could be written as

do
{
array1[i] = array2[k];
++i;
++k;
} while( array1[i-1] != '\0' )

-> array1[i] is tested for non-equality to '\0'

-> if TRUE array1[i] is incremented to array1[i+1]
No, i is incremented in the copy.
-> if TRUE array2[k] is incremented to to array2[k+1]
No, k is incremented in the copy.
-> if FALSE exit loop and neither k nor i is incrmented.

No, i and k will have been incremented.

--
Ian Collins.
May 2 '06 #2
mdh

Ian Collins wrote:
-> array1[i] is tested for non-equality to '\0'


Ian,

am I correct in that array1 NOT array2 is tested for inequality to
'\0'?

Thanks.

May 2 '06 #3
mdh wrote:
Ian Collins wrote:

-> array1[i] is tested for non-equality to '\0'

Ian,

am I correct in that array1 NOT array2 is tested for inequality to
'\0'?

It's the result of the assignment operation that is tested.

--
Ian Collins.
May 2 '06 #4
Ian Collins wrote:
mdh wrote:
Ian Collins wrote:
-> array1[i] is tested for non-equality to '\0'

Ian,

am I correct in that array1 NOT array2 is tested for inequality to
'\0'?


It's the result of the assignment operation that is tested.

Which incidentally is why we have the common assignment rather than
comparison bug,

if( i = 42 )

--
Ian Collins.
May 2 '06 #5
mdh

Ian Collins wrote:
It's the result of the assignment operation that is tested.

Ian, this is all rather new to me. Naively I thought that the array
was compared to '\0' so I am not quite sure by what you mean with
"result of the assignment operation". Is it possible to make your
explanation a little more concrete. Thank you

May 2 '06 #6
mdh wrote:
Ian Collins wrote:

It's the result of the assignment operation that is tested.


Ian, this is all rather new to me. Naively I thought that the array
was compared to '\0' so I am not quite sure by what you mean with
"result of the assignment operation". Is it possible to make your
explanation a little more concrete. Thank you

OK,

I might get some terms wrong, but others will correct me if I do...

(a = 42) is an assignment expression, the result of the expression is 42
.. The parenthesis ccreate a sequence point, like a hidden temporary
variable.

So if we have if( (a=b) == 0 )

this is equivalent to

temp = (a=b)
if( temp == 0 )

--
Ian Collins.
May 2 '06 #7
mdh

Ian Collins wrote:

(a = 42) is an assignment expression, the result of the expression is 42
. The parenthesis ccreate a sequence point, like a hidden temporary
variable.

So if we have if( (a=b) == 0 )

this is equivalent to

temp = (a=b)
if( temp == 0 )

Thanks Ian....I "think" I understand :-)

May 2 '06 #8
mdh wrote:
Ian Collins wrote:
(a = 42) is an assignment expression, the result of the expression is 42
. The parenthesis ccreate a sequence point, like a hidden temporary
variable.

So if we have if( (a=b) == 0 )

this is equivalent to

temp = (a=b)
if( temp == 0 )


Thanks Ian....I "think" I understand :-)

Once you understand the concept of an assignment yielding a result, the
fog clears...

--
Ian Collins.
May 2 '06 #9
Ian Collins wrote:
mdh wrote:
Ian Collins wrote:

It's the result of the assignment operation that is tested.
Ian, this is all rather new to me. Naively I thought that the array
was compared to '\0' so I am not quite sure by what you mean with
"result of the assignment operation". Is it possible to make your
explanation a little more concrete. Thank you

OK,

I might get some terms wrong, but others will correct me if I do...

(a = 42) is an assignment expression, the result of the expression is 42.


Correct.
The parenthesis ccreate a sequence point, like a hidden temporary
variable.

So if we have if( (a=b) == 0 )

this is equivalent to

temp = (a=b)
if( temp == 0 )


Absolutely not. Parenthesis do not introduce sequence points, the
following is undefined:
a = (a++);

where as this is not:

temp = a++;
a = temp;

Robert Gamble

May 2 '06 #10

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

Similar topics

9
4963
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
1
4729
by: Hohn Upshew | last post by:
I have a function for rating the clients depending on their quantity which works perfectly. My only problem is that my second function called GetSize is not recognized, and i need it in order to differentiate between packs smaller than 6 liters and packs which are 205 liters.I have tried to achieve that with the following formula : Public Function GetSize() Select Case Forms!!
20
2494
by: Brian Tkatch | last post by:
An ORDER BY a simple-integer inside a FUNCTION, results in SQL0440N, unless the FUNCTION expects an INTEGER as its parameter. For example: DECLARE GLOBAL TEMPORARY TABLE A(A CHAR(1)) INSERT INTO SESSION.A VALUES ('a'), ('b') CREATE FUNCTION A(A char(1)) RETURNS char(1) DETERMINISTIC NO EXTERNAL ACTION RETURN A SELECT A FROM SESSION.A ORDER BY A(1) DROP FUNCTION A DROP TABLE SESSION.A
21
4120
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
3
1563
by: Zongjun Qi | last post by:
Hey, In the book <Effective C++>, the author provides an example to prove why we need "pass by reference". I redoed the example, and found something interesting. The codes are: ############################## #include <iostream> class Student{ public:
0
4970
debasisdas
by: debasisdas | last post by:
CUME_DIST:- ============= THIS FUNCTION CALCULATES THE RATIO OF THE NUMBER OF ROWS THAT HAVE A LESSER OR EQUAL RANKING TO THE TOTAL NO OF ROWS IN THE PARTITION. PERCENT_RANK:-THIS FUNCTION CALCULATES THE RATIO OF THE ROW'S RANKING TO THE NUMBER OF ROWS IN THE PARTITION USING THE FORMULA (RRP-1)/(NRP-1) RRP-RANK OF ROW IN PARTITION. NRP-NUMBER OF ROW IN PARTITION. BOTH OF THESE FUNCTIONS UTILIZE DENSE_RANK FOR THEIR RANKINGS AND CAN...
0
4648
debasisdas
by: debasisdas | last post by:
REPORTING FUNCTIONS ALLOW THE EXECUTION OF VARIOUS AGGREGATE FUNCTIONS AGAINST A RESULT SET.UNLIKE WINDOWING FUNCTIONS THESE CAN'T SPECIFY LOCALISED WINDOWS AND THUS GENERATE THE SAME RESULT FOR EACH ENTIRE PARTITION.REPORTING FUNCTION GENERATES SAME RESULT AS A WINDOWING FUNCTION WITH AN UNBOUNDED WINDOW. Sample Ex#1 ------------------------- SELECT HIREDATE,SUM(SAL) "SALARY",SUM(SUM(SAL)) OVER (ORDER BY HIREDATE ROWS BETWEEN UNBOUNDED...
0
3899
debasisdas
by: debasisdas | last post by:
WINDOWING FUNCTION:- ==================== ORACLE'S WINDOWING FUNCTIONS ALLOW AGGERGATES TO BE CALCULATED FOR EACH ROW IN A RESULT SET BASED ON A SPECIFIED WINDOW.THE AGGREGATION WINDOW CAN BE DEFINED IN ONE OF THREE WAYS. 1.BY SPECIFYING A SET OF ROWS: 2.BY SPECIFYING A TIME INTERVAL: 3.BY SPECIFYING A RANGE OF VALUES: Sample ex#1 ------------------------
2
2805
by: mdock | last post by:
Hello, I have a javascript grid on my ASP page which displays information about the history of specific units produced in our manufacturing facility. One of the results is the order number on which the unit was shipped. If the unit was not shipped, obviously there is no order number; the default value of this field on the data table is 0. Herein lies the problem; if the order number is 0, I do not want the grid to display anything. If...
0
8662
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
9111
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9004
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
8961
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
7853
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
4421
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...
0
4679
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3114
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
2439
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.