# Create a struct with uninitialized fields

**URL:** https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967
**Category:** General Usage
**Tags:** struct, runtimegeneratedfunc
**Created:** [November 8, 2017, 9:12pm UTC](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967 "2017-11-08T21:12:00Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [October 10, 2021, 2:08pm UTC](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967/5 "2021-10-10T14:08:06Z")

</div>

I ended up with the following implementation:

```julia
"""
    __new__ (T, args...)
User-level version of the `new()` pseudofunction.
Can be used to construct most Julia types, including structs
without default constructors, closures, etc.
"""
@generated function __new__ (T, args...)
    return Expr(:splatnew, :T, :args)
end

```

I did’t try it with `undef` initializer, but given actual arguments, it works pretty well for quite a wide range if use cases in Ghost.jl. One caution though is that since `:new`/`:splatnew` are quite low-level, Julia won’t validate this expression, so misuse may lead to segfault.

---

_[View the full topic](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967)._
