• 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 21579
  • 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
Parents
  • 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
Reply
  • 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
Children
No Data
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