| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | #defines |
> Is there any way a code can be executed in a #if statement or outside a
> function ?
Code is never executed in preprocessor statements. The preprocessor merely
does textual substitution and static expression simplification, but it is
executed "in line" where it is instantiated in your code.
> I'm trying to refer to a memory location, and define two similar functions
> according to the value in there.
> I know a couple of other ways to do it, but i was trying to go..
> #define VAL *MK_FP(here,there)
> #if(VAL)
> #define func() func1()
> #else
> #define func() func2()
> #endif
If "VAL" can be evaluated by the preprocess (as in a mathematical
expression, or something else than can be statically evaluated at compile
time, then the answer is yes, this will do what you want. Since you imply
that "VAL" evaluates to code, then no, you can't do it.
What I think you're trying to do can, however, be achieved via
pointer-to-function - for example:
extern void func1(void);
extern void func2(void);
.
.
void (*fptr)(void);
if (*MK_FP(here,there)) /* Or VAL if this is your preferred obfuscation */
fptr = func1;
else
fptr = func2;
.
.
(*fptr)(); /* All func1 or func2 via pointer, which can also
be expressed fptr() - ie. without the brackets
and the indirection */
.
.
--- MaltEd/2 1.0.b6
* Origin: Unique Computing Pty Limited (3:632/348)SEEN-BY: 633/267 270 @PATH: 632/348 635/503 50/99 635/728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.