# \`nfields\` giving incorrect number of fields

**URL:** <https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [November 13, 2018, 7:01pm UTC](https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489 "2018-11-13T19:01:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 13, 2018, 7:01pm UTC](https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489/1 "2018-11-13T19:01:09Z")

</div>

The following seems like a bug to me.

```julia
julia> struct MyType
           a
           b
           c
           d
           e
           f
           g
           h
           i
           j
           k
           l
           m
           n
           o
           p
           q
           r
           s
           t
           u
           v
           w
           x
           y
           z
       end

julia> nfields(MyType)
20

julia> length(fieldnames(MyType))
26

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 13, 2018, 7:03pm UTC](https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489/2 "2018-11-13T19:03:09Z")

</div>

Ahhh, I think I got it. It actually counts the fields of the `DataType` object `MyType`. There, 20 is correct.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 13, 2018, 7:03pm UTC](https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489/3 "2018-11-13T19:03:53Z")

</div>

[https://github.com/JuliaLang/julia/issues/29977](https://github.com/JuliaLang/julia/issues/29977)

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 13, 2018, 7:06pm UTC](https://discourse.julialang.org/t/nfields-giving-incorrect-number-of-fields/17489/4 "2018-11-13T19:06:25Z")

</div>

Ok, so `fieldcount(MyType)` gives me what I want. Somewhat confusing indeed.
