0
\$\begingroup\$

I am fairly new to Verilog and can’t find out if Verilog modules have same scope privacy as for example C functions have. For example can I use same name ( say clk ) for variables in different modules ?

asked Aug 6, 2021 at 21:01
\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

Verilog has several name spaces for different kinds of constructs. See Section 3.13 Name spaces in the IEEE 1800-2017 SystemVerilog LRM.

Briefly, each module definition creates a name space for itself and you can declare variable with the same names within each module. There is no implicit connection between variables with the same name in different modules, you must connect them through ports. Within a module you can have other local scopes and declare variables with the same name inside them. (like inside a function)

You might want to read my DVCon paper about variable scopes and lifetimes.

answered Aug 6, 2021 at 22:47
\$\endgroup\$
1
\$\begingroup\$

Signals declared inside a module have their scope local to that module only. So, yes, two different modules in a source file can have signals with same name, with corresponding local scopes.

However, recommended coding practice - single module in a single source file.

answered Aug 6, 2021 at 21:17
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.