Jump to content

string literal spanning a newline (using a backslash) - vendor supported?


Recommended Posts

A backslash can be used to extend a string literal onto the next line if "the new line is immediately preceded by a \ (backslash)."

    Section 5.9 of 1800-2012.pdf, the SystemVerilog LRM


I don't think I have ever been able to get this work and w/o looking I seem to recall it has been in Verilog/SystemVerilog for a while.


Can someone tell me if vendors support this and perhaps correct the code below on edaplayground?


example from LRM:

$display("Humpty Dumpty sat on a wall. \
Humpty Dumpty had a great fall.");

See example here (on Sept 29, urls below are updated in response to Tudor comment below.  thx.):


https://www.edaplayground.com/x/4Tyw    //if the above does not work, try this one, with https://

Link to comment
Share on other sites

Thanks, Tudor and Dave.

*) I updated the urls, per Tudor comment.

*) Aldec and Mentor simulators were the two that I did not use.  I now tried Aldec on edaplayground and see that it works.  Unfortunately, with regards to this SV feature, I'm not using either of these simulators.  Can anyone confirm that neither Cadence nor Synopsys support this?  (Well, I guess I've figured out that they don't, now that I have witnessed at least one simulator support it.  Aldec's.)




Link to comment
Share on other sites

I think the problem is with EDAplayground.com appending extra characters at the end of each line. Look carefully at the error messages coming from each tool and you'll see a good explanation of the problem. I believe Aldec is incorrectly ignoring that extra character, so it appears that it is "working".

Link to comment
Share on other sites

Yes, thanks Dave.  (I shouldn't assume everyone I've seen on here monitors all the threads.)

Feedback from Victor (the creator of edaplayground) on the edaplayground forum:

I've seen this before. The server uses "\r\n" DOS line endings, and some simulators don't grok these. The fix for EDA Playground would be to use "\n" line endings instead of "\r\n"
You can see this by using "Download files after run"
Link to comment
Share on other sites

  • 1 year later...

From http://www.asic-world.com/systemverilog/literal_values4.html


    string  a;
    a = "This is multi line comment \n
         and this is second line";



    a = This is multi line comment^M
            and this is second line


//You will have ^M which is the dos character for new line. if you write to a file with this line. If you want to avoid that, then the next solution should be used

    string tmg ={" \n"                                               ,
        "//periodic signal intf.KEYCONTROL_CLK \n"         ,
        "fork\n"                                           ,
        "   begin\n"                                       ,
        "     the_clock = 0;\n"                            ,
        "     forever begin\n"                             ,
        "       if(the_clock == 0)\n"                      ,
        "          #(5000000/2 * 1ps);\n"                  ,
        "       else\n"                                    ,
        "          #((5000000-5000000/2) * 1ps);\n"        ,
        "       the_clock=~the_clock;\n"                   ,
        "     end\n"                                       ,
        "   end\n"                                         ,

        $display ( tmg);


Obviously, the second example is recommended

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...