Dictate order that operands are evaluated in c -


the statement puts("a") + puts("b") undefined. because not specified in c standard whether these ought executed left right or right left get

a b 

or

b 

is there clean way dictate order of operations in expression?

the thing can think of use compound statement such as

({     int temp = puts("a");     temp += puts("b");     temp; }) 

though non-portable , little longer hoping.

how best achieved?

if declare int variable before expression, can force order portably comma operator while computing sum inside expression:

int temp; ...  (temp = puts("a"), temp + puts("b")) 

as specified in c standard:

6.5.17 comma operator

syntax

 expression:      assignment-expression      expression , assignment-expression 

semantics

the left operand of comma operator evaluated void expression; there sequence point between evaluation , of right operand. right operand evaluated; result has type , value.

note value of expression not useful given semantics of puts(), commented jonathan leffler.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -