• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. A printf wrapper

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 13531
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A printf wrapper

mb47
mb47 over 17 years ago

Dear skilled cadencers,

I'd like to write a wrapper for the printf() function. The problem is
that I do not know how to have a variable number of arguments. I tried
with @rest:

procedure( myPrint(port str @rest args)
    fprintf(port str args)
    newline(port)
)

however this won't work because args is a list and fprintf (or printf)
complains about that.
How can I achieve this task?

Thanks,
mb

 

  • Cancel
  • dmay
    dmay over 17 years ago

    Take a look in the Skill Language Reference Index for "Comma-At" documentation. With this syntax you can get your function working:

    procedure( myPrint(port str @rest args)
        apply('fprintf `(,port ,str ,@args) )
        newline(port)
    )
    port = outfile("/tmp/test.txt")
    myPrint(port "Hello %s %d" "derek" 1)
    myPrint(port "Hello %s %d" "joe" 2)
    myPrint(port "Hello %s %d" "zeke" 3)
    close(port)

    The documentation states:
    In absence of commas and the comma-at (,@) construction, backquote functions in exactly the same way as single quote. However, if a comma appears inside a backquoted form, the expression that immediately follows the comma is evaluated, and the result of evaluation replaces the original form.
    The comma-at construction causes evaluation just as the comma does, but the results of evaluation must be a list, and the elements of the list, rather than the list itself, replace the original form.

     -Derek

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information