• 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. Adams
  3. C++ subroutines and global variables

Following Cadence Design Systems’ acquisition of the Design & Engineering (D&E) business, the D&E Community Forum on the Nexus Community Center has been migrated in the Cadence Physical System Simulation Community. For more details and if you have any questions, please refer to the FAQ.

Stats

  • State Not Answered
  • Replies 1
  • Subscribers 3
  • Views 1
  • Members are here 0
More Content

C++ subroutines and global variables

Josef K.
Josef K. over 3 years ago
Hi,
 
I use a C++ subroutine for the GFORCEs in one of my models. There are three GFORCEs in the model and as such, the same subroutine is called multiple times at the same timestep. I want to make sure that the values of certain variables are not mixed between forces so I used global variables for these.
 
My question is, if I define the initial value for a global variable inside the main(), will that be called only once when loading the .dll, or will it never be called if I dont explicitly do so?
 
Also, since I also want to use a unique number (such as the force ID) when initializing these global variables, is the id made avalaible to the before actually calling the force function insed the dll?
 
Thanks,
 
Josef
 
  • Sign in to reply
  • Cancel
  • Jesper Slattengren
    0 Jesper Slattengren over 3 years ago
    Use the IFLAG to set initial values. You might get several calls when IFLAG is true, but all before start of the simulation.
    It is bad habit to hardcode initial values, better to send the value as a parameter to the subroutine.
     
    Use the ID to index all global data. Build an index when IFLAG is called by looping over an array ID_index (for example). If ID does not exist in ID_index, append ID. Then at each call check the index for ID in ID_index and you have your index into all global arrays. No problem using this method even with hundreds of GForces using the same subroutine.
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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.

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

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