# "if" evaluated at compile time

**URL:** https://community.freefem.org/t/if-evaluated-at-compile-time/2928
**Category:** Feature Request
**Created:** [February 3, 2024, 10:50am UTC](https://community.freefem.org/t/if-evaluated-at-compile-time/2928 "2024-02-03T10:50:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [February 3, 2024, 10:50am UTC](https://community.freefem.org/t/if-evaluated-at-compile-time/2928/1 "2024-02-03T10:50:51Z")

</div>

Hello to everybody  
Is there any way to have an “if” test evaluated at compile time?  
I would like to have the following type of code to work

```auto
int n=30;
mesh Th=square(n,n);

int algo=2; // possible values 1,2,3

if (algo==1){
fespace Uh(Th,P1);
fespace Ph(Th,P0);
}
else if (algo==2){
fespace Uh(Th,P2);
fespace Ph(Th,P1);
}
else if (algo==3){
fespace Uh(Th,P2);
fespace Ph(Th,P1dc);
}
else {
cout << "undefined algorithm " << endl;
}

Uh u,v,uu,vv;
Ph p,pp;

// etc

```

This produces an error at compilation: “Uh The Identifier Uh does not exist”.  
It seems that at compile time the “if” is not evaluated, and the “fespace” declaration is not applied.  
Any solution to be able to do such multi-task coding ?  
Thank you.

---

<div class="post-metadata">

### Author: ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)
#### Post date: [February 3, 2024, 12:52pm UTC](https://community.freefem.org/t/if-evaluated-at-compile-time/2928/2 "2024-02-03T12:52:24Z")

</div>

You should use [macros](https://doc.freefem.org/references/types.html#newmacro-endmacro)

```auto
macro algo( )2// End Of Macro  

IFMACRO(algo,1)
fespace Uh(Th,P1);
fespace Ph(Th,P0);
ENDIFMACRO
IFMACRO(algo,2)
fespace Uh(Th,P2);
fespace Ph(Th,P1);
ENDIFMACRO

```

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [February 3, 2024, 2:18pm UTC](https://community.freefem.org/t/if-evaluated-at-compile-time/2928/3 "2024-02-03T14:18:41Z")

</div>

Thank you, this is very helpful in order to avoid having many codes with similar content!  
Best,  
Francois.
