# Function arguments not initializing variable inside the body

**URL:** <https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, functions-in-system-verilog\
**Created:** [June 2, 2016, 6:53pm UTC](https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889 "2016-06-02T18:53:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 3, 2016, 12:35am UTC](https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889/2 "2016-06-03T00:35:36Z")

</div>

_In reply to [sanjeevs](https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889):_  
Your failing code is illegal according to the SystemVerilog 1800-2012 LRM. (see 6.21 Scope and lifetime). Your simulator should have generated an error.

You are not allowed to have an initialization on a variable whose lifetime is implicitly static and has the option to be declared automatic. This is because unlike most programming languages, the default lifetime of variables in a function is static, and initialization of static variables happens before time 0, not when calling the function. In your example, you are expecting **i** to behave as an automatic. So you need to do one of the following

- explicitly declare i automatic
- declare the function automatic, which makes variable declared inside it implicitly automatic
- declare the module automatic, which makes functions declared inside it implicitly automatic
- split the declaration and initialization so that the initialization happens when the function gets called.

Also see [When should be program block dynamic or static ? members of static program block , members of automatic program blocks ? | Verification Academy](https://verificationacademy.com/forums/systemverilog/when-should-be-program-block-dynamic-or-static-members-static-program-block-members-automatic-program-blocks#reply-38825)

---

_[View the full topic](https://verificationacademy.com/forums/t/function-arguments-not-initializing-variable-inside-the-body/31889)._
