bobc@attctc.Dallas.TX.US (Bob Calbridge) (10/07/89)
This is something that passed through my mind and I thought I's ask the wizards here if it is possible. Though I've been working with C on and off for a couple of years I don't get the chance to get deeply involved with extremely complex programs. Therefore, when, from time to time, I see a clever use of the flexibility of the language I get intrigued with the possibilities. So I ended up with the question as to where a function may be used in expressions. Mainly, can it be used anyplace that a variable or a constant may? One example that came to mind, though I have no immediate concept of how it might be used, is can a function be used as the argument to a case statement? For example: switch (expression) { case f1(): do_this(); break; case f2(): do_that(); and_that(); case f3(): while (youre_at(it)) { take_out(the_garbage); put_out(the_cat); }; break; case adnauseum: honk(); } where f1...fn() may be functions that evaluate circumstances and return an integer or get input from the user and return an integer. I have vague ideas as to why something may be implemented this way, if it is even possible. I just don't have an immediate need, just an immense curiosity. Is the language that flexible or is it possible to violate this concept? -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- = I know it's petty.......... = - But I have to justify my salary! - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cpcahil@virtech.UUCP (Conor P. Cahill) (10/07/89)
In article <9604@attctc.Dallas.TX.US>, bobc@attctc.Dallas.TX.US (Bob Calbridge) writes: > switch (expression) { > case f1(): do_this(); > > where f1...fn() may be functions that evaluate circumstances and return an > integer or get input from the user and return an integer. This is not allowed. The expression in a case statement MUST be a constant expression. A function call is not a constant. It looks like you are back to the old if-then-else stuff. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+