# Is it possible to get the fieldnames of a struct inside a macro?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314>\
**Category:** General Usage\
**Created:** [January 13, 2020, 8:44pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314 "2020-01-13T20:44:53Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [January 13, 2020, 11:12pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314/15 "2020-01-13T23:12:34Z")

</div>

Sorry, I’m on a phone right now so I can’t run code, but try something like this:

```julia
function foo(T)
  @doit(T)
end

```

The macro just gets the symbol T. It has _no access_ to the value that T is bound to when you call `foo`. After all, you haven’t even called `foo` yet, so how could it?

The given example happens to work because it only involves global variables that were already defined at the time the macro was expanded. You can’t rely on that being the case.

---

_[View the full topic](https://discourse.julialang.org/t/is-it-possible-to-get-the-fieldnames-of-a-struct-inside-a-macro/33314)._
