• 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. Allegro X PCB Editor
  3. printf() as first line and number formatting

Stats

  • Replies 14
  • Subscribers 160
  • Views 21572
  • Members are here 0
More Content

printf() as first line and number formatting

EvanShultz
EvanShultz over 16 years ago

OK, here's a weird one for you. I want to print some information for the user into the Command window before I do anything else. So, I figured why not make a printf() statement the very first line of code? I suppose it should work - George does it on lines 25-35 of tekTechFileXML.il (from SourceLink). But for me, nothing is printed in the Command window. If I move the exact same statement as the first line of the procedure(), the text is printed to the Command window.

So what's my problem? Well, farther down in the procedure() a subroutine is called which uses axlEnterPath(). And the "Enter first point" prompt from axlEnterPath() comes BEFORE my printf() text, even though the printf() comes first in the code. My mind is boggled. I changed the prompt for axlEnterPath so I know it is this SKILL function that is creating the prompt which is jumping ahead of my printf() text.

Any ideas why this SKILL function can't wait it's turn? Or, better yet, how can I get the string in a printf() statement to show in the Command window if the printf() statement is the very first line of the SKILL routine?

 

 Secondly, I want to print out a table of information which may be integers or floating point numbers. How can I do this while keeping the table nicely lined up? Here is what I've found:

%-10n - displays both number types, but pads with zeros for floating point numbers

%-10g or %g - barfs on integers

%-10L or %L - displays both number types, no padding zeros for fp, but ignores [width] field (as per page 170 of sklangref.pdf)

So, what options do I have? I want similar to %-10n output, but without zero padding. %-10g would seem to be the right choice. I've used %g in other SKILL programs and it gracefully handled both integer and fp numbers - any ideas why it isn't with integers for me now?

  • Sign in to reply
  • Cancel
  • EvanShultz
    EvanShultz over 16 years ago

     Hi Lawrence,

     Thank you for the reply. What I am trying to accomplish is to make object_str an empty string when it is nil. I am creating a CSV file, using Extracta data, and on some footprints there is no footprint property so get nil for object_str. But I have to have a string, as I am printing object_str to the CSV file using "%s". So I used sprint(...) to create an empty string in the case where object_str is nil (so I have 2 consecutive commas in the CSV file).

    The line of code I posted works fine, it's just that Lint doesn't like it. Is there another way to accomplish the same thing?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • skillUser
    skillUser over 16 years ago

    Hi Evan,

    Ok, now I understand a little more about what you are trying to do.  I think that you could use the return value of the cond statement and achieve what you want that way.  Example:

    object_str = cond(
        (integerp(object) sprintf(nil "%d" object))
        (floatp(object) sprintf(nil "%g" object))
        ;; if the object is 'nil' or any unhandled case, return empty string
        (null(object) "")
        (t "")
    )

    There are still many ways that this could be done, but I believe that the above is readable and clear, and would be easy to extend if another format was needed at a later date.  The "null(object)" clause is unnecessary since the catchall (the 't' clause) provides the same result, but sometimes it is good to be verbose so that anyone reading the code is clear on the intent.

    I hope that this helps avoid any Lint trouble :-)

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • EvanShultz
    EvanShultz over 16 years ago

     Hi Lawrence,

     Thank you. I was able to make it ever simpler using just an if/else statement with the else being:

    object_str = ""

    in order to get an empty string. The code works as well as it did when I used sprintf but now my Lint IQ is 100. Thanks for you help!

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • skillUser
    skillUser over 16 years ago

    Hi Evan,

    Glad to have been some help, and that you now have the max Lint score.

    I would point out to all that SKILL Lint is a useful tool to measure the "goodness" of code, but it is entirely possible to write "bad" code which achieves a score of 100. And the converse is true also, that very good code may receive a score of less than 100 due to some nuances in the way that things are measured - sometimes there can be tricks to improve the score.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
<
Cadence Guidelines

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