Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: #include (but no #includeOnce).... Any gotchas to watch out for?
Topic Summary:
Created On: 12-Sep-2008 21:20
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 12-Sep-2008 21:20
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Just curious... some languages have an "includeOnce" function, that ensures that each library is included just once. In DXL, if I have a heirarchy of function libraries, some higher-level libraries that include lower-level libraries, do I need to have any concern that I might be including some libraries more than once. I'm guessing there is no real down-side, but you never know....
Report this to a Moderator Report this to a Moderator
 13-Sep-2008 00:27
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

A follow-up question... can you put #include statements within functions?

Something like...
void doAdvancedFunction() {
#include <lowLevelFunctions.inc>
doLowLevelFunction1
doLowLevelFunction2
}

So far, my early testing seems to show you can. It appears, #include statements within functions don't get exectued until the function is actually called.

Anyone do this regularly? Any side-effects to watch out for?
Report this to a Moderator Report this to a Moderator
 15-Sep-2008 08:39
User is offline View Users Profile Print this message


Paul Howstan

Posts: 47
Joined: 27-Sep-2006

Hi David,

My understanding of #include is that it could literally be replaced with the code from the file you are including, so in that sense, the #include can go anywhere so long as the resultant code is correct. What you will probably find by using a #include within a function is that variables and functions declared in the include file are only scoped to the function you had the #include statement in (in your example, doAdvancedFunction).

So... if you had a function that included a file which declared a variable, that variable would only exist while you are inside the calling function, once you exit the calling function, the variable is terminated. Calling the function again will create a new variable and the value of the old instance will be lost.

An example:

------------------------------------
aFile.inc:
string test = "Hello"
------------------------------------
main DXL file:
void doSomething()
{
#include aFile.inc
print test
}

doSomething //this is valid
print test //this is not as test no longer exists out of the scope of the doSomething function
-------------------------------------

The same applies to functions, any function declared within another function is terminated once the calling function completes.

Regards,

Paul

Edited: 15-Sep-2008 at 08:40 by Paul Howstan
Report this to a Moderator Report this to a Moderator
 15-Sep-2008 13:32
User is offline View Users Profile Print this message


Tony Goodman

Posts: 97
Joined: 6-May-2008

I never use nested #includes and I have a simple rule that I only ever put #include statements in *.dxl files, not in *.inc files.

When an *.inc file relies on another *.inc, I might include a comment in the header.

With respect to libraries of functions, I am reluctant to rely too heavily on "kitchen style" utility files. It is all too easy to have your dxl break when some library routine is missing or has changed.

To this end I make most scripts self-contained with their own set of *.inc files, normally stored in folder called inc next to the main *.dxl file.

-------------------------
Tony Goodman
Smart DXL limited
www.smartdxl.com
Report this to a Moderator Report this to a Moderator
 15-Sep-2008 17:42
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Thanks. For the most part, I do pretty much what Tony describes, up until now.

I don't nest #includes and I ususally put the includes at the top of the .dxl file. Each #inlclude file is just a group of related functions. And, if there are any depenendcies among the #include files, I just note that with // style comments to the left.

I don't actually have a common library, but rather I copy the entire library when I start a new high-level function and add/replace the libraries I need. As a result, I have non-common libraries. So I have issues such as: 1) if I improve a function in one place, I need to go hunting in the other libraries that have a similar function, 2) a function in one context may not work the same as in another, because of different libraries

I've thought that maybe I should work towards one set of common library files. Although, as I think Tony is describing, then you might update a function for some newer application, but break older applications becuase the function doesn't work the same any more.
Report this to a Moderator Report this to a Moderator
 15-Sep-2008 19:27
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

Actually what I've found is that #include statements are executed before any other code, no matter where they are in the code.

To place a #include inside a function to only be executed when that function is called you would need to use the eval_ () command.

-------------------------
Scott Boisvert
Engineering Tools Administrator
L-3 Communications - Avionics Systems
scott.boisvert@l-3com.com
Report this to a Moderator Report this to a Moderator
 15-Sep-2008 20:04
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Scott and Paul... you guys are correct, and I was wrong in my earlier post.... it seems #include statements are pre-processed before any DXL. So, if you put the #include statement within a function, it's just as if you put all the actual code in the same spot. So, while you can put #include statements within a function... the included functions simply become locally-declared functions of the parent function. Not really a whole lot of benefit.

I'm guess I'm looking for a "best practice" when mananging large sets of library files.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.