5
\$\begingroup\$

So I was writing some verilog in quartus and wondering why the heck it was misbehaving.

I eventually discovered the problem was some constants where I had inadvertantly used a backtick instead of a single quote. For example I had 32`hdeadbeef instead of 32'hdeadbeef.

What I find surprising is that this compiled, did I find a bug in quartus? is this some obscure bit of verilog syntax? if so what does it mean?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

I have just been reading the IEEE standard about macro's and defines. There is nothing in there which says that the macro name must be known. (In your case `hdeadbeef would not match any define).

However I can imagine them not defining that as that would be too far fetched.

Using common sense I would say it is a bug in the parser.


Speculating:
The following is allowed:

`ifdef this_variable_is_not_defined

So maybe the code for that got also used for `this_macro_does_not_exist

\$\endgroup\$
4
  • \$\begingroup\$ It does seem quite plausible that it is treating the unknown macro as an empty string and then treating the number that was supposed to represent the width as a straight decimal constant of default width. \$\endgroup\$ Mar 9, 2018 at 19:35
  • \$\begingroup\$ That is what I was assuming. Just tried it in Vivado but there I get an error message. \$\endgroup\$
    – Oldfart
    Mar 9, 2018 at 19:38
  • \$\begingroup\$ I haven't tried Vivado but I have noticed in the past that Quartus is a lot less strict about Verilog than Modelsim is. \$\endgroup\$ Mar 9, 2018 at 19:42
  • 1
    \$\begingroup\$ The LRM says "After a text macro is defined, it can be used in the source description by using the (`` ` ``) character, followed by the macro name." I understand this to mean "before a text macro is defined, it cannot be used ..." Otherwise, a simple misspelling of a compiler directive, like `celdefine would go unnoticed. This is the only rational behavior. \$\endgroup\$
    – dave_59
    Mar 10, 2018 at 5:29
2
\$\begingroup\$

This is most likely a bug and should have been an error . The backtick ` is only used in with compiler directives

\$\endgroup\$
4
  • \$\begingroup\$ Yes, and one of those directives is `define <name> -- and when you want to use <name> in a statement, you say `<name>. Not a bug. \$\endgroup\$
    – Dave Tweed
    Mar 9, 2018 at 23:18
  • 1
    \$\begingroup\$ @DaveTweed that assumes someone already has the statement `define deadbeef in their code, which I doubt \$\endgroup\$
    – dave_59
    Mar 10, 2018 at 0:27
  • \$\begingroup\$ No, it doesn't. It's perfectly OK to refer to an undefined symbol, which expands to nothing. \$\endgroup\$
    – Dave Tweed
    Mar 10, 2018 at 1:52
  • 2
    \$\begingroup\$ Not true. You should get an undefined compiler directive or macro. Try it. \$\endgroup\$
    – dave_59
    Mar 10, 2018 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.