| Just A Small C Question [JustASC] 2 |
|
Moderator
![]()
|
Whats the matter guys...no replies today???
atleast try.... |
||||||||||||||||
|
|
|||||||||||||||||
|
Regular Member
![]()
|
is it by DO WHILE and if not then plz tell the answer on my private message
|
||||||||||||||
|
|
|||||||||||||||
|
Moderator
![]()
|
@rahul: the answer that i have in mind doesnt have anything to do with a do while statement, neither can i think of a way with which i can make a more conciser solution using do while...Please share with us what u exactly had in mind cuz I may be wrong and that'll make me learn too...
Neways, the answer that i have will be put on the forum in a day or two, so can't PM u right now...just wait a bit... |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
Don't know dude...
Only thing I can think of is to remove the braces.. if(a== b) c=d; |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
well, i'll give you a hint...
The solution will convert the if block into a single statement. This is true for ur answer too, navjot, but only when there is a single statement inside the braces. The solution that i've in mind will work for multiple statements inside the braces too, and convert the whole block into a single statement...(BTW, the "if" keyword won't be there in that solution, that much i can tell u.) |
||||||||||||||||
|
|
|||||||||||||||||
|
Groupie
![]()
|
maybe something of sort
( a==b ? c ? x) plz make clear that can we assume a value in else case |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
@whacko: I have already mentioned it there should is "no" else statement, so you can't assume anything for that..
|
||||||||||||||||
|
|
|||||||||||||||||
|
Groupie
![]()
|
using the macros
#define (a==b) (c=d); |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
@whacko: I cudnt understand how ur last solution wud achieve the purpose...
Neways, the solution has to support multiple lines withing the if block too.. |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
OK, so I just saw this and I have some comments and some questions.
1) Are you asking us what the compiler *could* do to optimize this code block or what it definitely *will* do? 2) Are you sure we don't need to know any other information about the relationships between a,b,c and d? In any case, here are a few comments: * If the compiler can figure out earlier in the program (by constant folding, CSE, SSA and other techniques) that a will *never* be equal to b, then it can do what's called "dead code elimination" and basically remove that entire block (since it's dead code) but this doesn't seem like what you want. * Hmm ... if you don't have any information about whether the boolean expression (a==b) evaluates to True or False, then I can't think of what sort of optimizations you can apply at compilation time. If you have given us all the information that we needed to know, then I am stumped ! |
||||||||||||||||
|
|
|||||||||||||||||
|
Privileged Member
![]()
|
c=a=b?d:c;
not my answer.. one of my cubicle mate saw t his post and said this will be the reply!!!! |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
@wicked_sunny:
sorry, wrong answer on four accounts: 1. This statements will always give a true result and c will always be equal to d. It should be written as c=(a==b)?d:c; 2. Even then, it includes an "else" part (":c") which i have specified in the problem that it shouldn't be there... 3. It is only true for the simple case of an assignment statement present within the if block (which i gave as an example) while i've specified that the block can have any type of arithmetic statements. 4. It can't be used for multiple statements within the if block.... |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
Oh you have to got to be kidding me !! That's all you wanted ... boy, do I feel dumb !! I think the answer should be this:
(a==b) && (c=d); The first boolean subexpression short-circuits the entire thing if it's not true and therefore 'c=d' is never evaluated unless a is equal to b. |
||||||||||||||||
|
|
|||||||||||||||||
|
Moderator
![]()
|
@nitin: Yupz u got it right once again...simple, isn't it??
and the beauty is that u can chain any no. of expressions to convert the whole block into a single statement... like (a==b) && (c=d) && (e=f+g) && (h=i*4); etc etc.... Since after the first condition (u can even chain conditions), all the expressions evaluate to true so all of them will be evaluated... New question soon... |
||||||||||||||||
|
|
|||||||||||||||||
|
||
Copyright © 2005 PECOBIANS.COM. All rights reserved
Site Maintained & Developed by Lord PEC
Disclaimer | Privacy Policy
Based on phpBB © phpBB Group & PS




