# Fespace Vh as the input argument of a function

**URL:** <https://community.freefem.org/t/fespace-vh-as-the-input-argument-of-a-function/4121>\
**Category:** General Discussion\
**Created:** [November 3, 2025, 9:01am UTC](https://community.freefem.org/t/fespace-vh-as-the-input-argument-of-a-function/4121 "2025-11-03T09:01:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MatrixVector](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@MatrixVector](https://community.freefem.org/u/MatrixVector)\
**Post date:** [November 3, 2025, 9:01am UTC](https://community.freefem.org/t/fespace-vh-as-the-input-argument-of-a-function/4121/1 "2025-11-03T09:01:32Z")

</div>

Is it possible to set the `fespace` itself as an input argument of a self-defined `func` function? My problem is related to the node id of the `fespace`, and a simplified example is as follows:

```cpp
mesh Th = square(2, 2);
fespace Wh(Th, P2);

for (int k = 0; k < Th.nt; k++) {
    for (int i = 0; i < 6; i++) {
        int j = Wh(k, i);
        cout << j << " ";
    }
    cout << endl;
}

```

Is it possible to define a function and use the `fespace Wh` as an input argument? A test is as follows, but an error called `syntax error before token fespace` occurs.

```cpp
func int test(fespace Wh) {
    int j = Wh(0, 0);
    return j;
}

```

If it is not possible to implement such function, should the `mesh Th` be the input argument, or just define the `mesh` and `fespace` within the `func` function?

---

<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:** [November 3, 2025, 10:52am UTC](https://community.freefem.org/t/fespace-vh-as-the-input-argument-of-a-function/4121/2 "2025-11-03T10:52:24Z")

</div>

You can use a macro, since it uses literal (string) arguments without any check of their nature.

```auto
NewMacro funcofmesh(Whh)// macro with formal fespace as argument
func int Whh#test() {
    int j = Whh(0, 0);
    return j;
}
EndMacro

mesh Th = square(2, 2);
fespace Wh(Th, P2);

funcofmesh(Wh);// this defines the function "Whtest"
int jres=Whtest();
cout << "jres=" << jres << endl;

```

Another possibility is

```auto
NewMacro funcofmesh(Whh,res)// macro with formal fespace as argument
 res = Whh(0, 0);
EndMacro

mesh Th = square(2, 2);
fespace Wh(Th, P2);

int jres;
funcofmesh(Wh,jres);
cout << "jres=" << jres << endl;

```

---

<div class="post-metadata">

**Author:** ![MatrixVector](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@MatrixVector](https://community.freefem.org/u/MatrixVector)\
**Post date:** [November 3, 2025, 11:33am UTC](https://community.freefem.org/t/fespace-vh-as-the-input-argument-of-a-function/4121/3 "2025-11-03T11:33:51Z")

</div>

Dear Dr. Bouchut,

Thanks for your reply, and using the `macro` is a good solution.
