• 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. Weird "case" statement behavior (at least to me...), can...

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 143
  • Views 7490
  • 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

Weird "case" statement behavior (at least to me...), can someone please explain this to me?

Sheppy
Sheppy over 10 years ago

Hello all,

Today I ran into a problem which toke me a long time to find the cause. It is with the "case" statement. First I show you something that is very simple and that does work:


testString = "one"
case( testString
    ( "one"
        printf("it is 1!\n")
    )
    ( "two"
        printf("it is 2!\n")
    )
    ( t
        printf("it is something else!\n")
    )
)

testString = "two"
case( testString
    ( "one"
        printf("it is 1!\n")
    )
    ( "two"
        printf("it is 2!\n")
    )
    ( t
        printf("it is something else!\n")
    )
)

testString = "bla"
case( testString
    ( "one"
        printf("it is 1!\n")
    )
    ( "two"
        printf("it is 2!\n")
    )
    ( t
        printf("it is something else!\n")
    )
)


When you run this code (just copy-past into CIW...) the output of the case statements is as you would expect:

it is 1!
it is 2!
it is something else!

However, if you specify a variable like so:


testOptions = list( "one" "two" )


And replace the "case" statement with this:


case( testString
    ( nthelem( 1 testOptions )
        printf("it is 1!\n")
    )
    ( nthelem( 2 testOptions )
        printf("it is 2!\n")
    )
    ( t
        printf("it is something else!\n")
    )
)


The output is not what I expected:

it is something else!
it is something else!
it is something else!

Testing the "nthelem" part shows no problem, it perfectly outputs the right string (or whatever you put in the list).

If you do the same with a "cond" statement (using the "nthelem" statement), it works perfectly fine.

My question: what is happening here? Why is the result what it is, and not what I was expecting?

Thanks in advance.

With kind regards,

Sjoerd

  • Cancel
Parents
  • Sheppy
    Sheppy over 10 years ago

    Hi Andrew,

    Thanks for the explanation. Is it made this way for speed, or is there an other reason to implement it like this? If it is not evaluating, it is obviously much faster.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Sheppy
    Sheppy over 10 years ago

    Hi Andrew,

    Thanks for the explanation. Is it made this way for speed, or is there an other reason to implement it like this? If it is not evaluating, it is obviously much faster.

    With kind regards,

    Sjoerd

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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