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: In-line a string array into a function call?
Topic Summary:
Created On: 22-Jan-2008 20:03
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.
 22-Jan-2008 20:03
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Is it possible to put a string array directly in-line in a function call? This example will show what I mean:

// This works...
string ans[] = {"Yes","No"}
DB xDB = centered "Sample"
DBE xRadio = radioBox(xDB,"Your answer?",ans,0)
show xDB

// This does not work...
DB xDB = centered "Sample"
DBE xRadio = radioBox(xDB,"Your answer?",{"Yes","No"},0)
show xDB

Is there any proper syntax to do this?
Report this to a Moderator Report this to a Moderator
 22-Jan-2008 21:13
User is offline View Users Profile Print this message


Scott Boisvert

Posts: 348
Joined: 14-Apr-2006

I don't think it's possible, though I've been wrong before.

-------------------------
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
 23-Jan-2008 10:21
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

Surely, good programming practice would prohibit having string literals used in this way even if it were possible.

-------------------------
Tony Goodman
http://www.smartdxl.com
Report this to a Moderator Report this to a Moderator
 23-Jan-2008 15:35
User is offline View Users Profile Print this message


David Jakad

Posts: 94
Joined: 20-Jul-2007

Yes, it's probably not good programming practice. However, I run into all kinds of problems (memory corruption and DOORS crashes) when I try to define local string arrays inside of functions. The following set of simple DXL programs will highlight the issue.



// This works fine
DBE fnAddTab(DB xDB) {
void fnDoNothing(DBE xTab) {}
string options[] = {"One","Two"}
DBE xTab = tab(xDB,options,400,200,fnDoNothing)
return xTab
}
DB xDB = centered "Sample"
DBE xTab = fnAddTab(xDB)
show xDB


// This demonstrates corrupted tab labels
DBE fnAddTab(DB xDB) {
void fnDoNothing(DBE xTab) {}
string options[] = {"One","Two"}
DBE xTab = tab(xDB,options,400,200,fnDoNothing)
return xTab
}
DBE fnAddText(DB xDB) {
string xLabel = "This is some sample text"
string xInitial = "This is a bunch of meaningless text."
DBE xText = text(xDB,xLabel,xInitial,400,200,false)
return xText
}
DB xDB = centered "Sample"
DBE xTab = fnAddTab(xDB)
DBE xText = fnAddText(xDB)
show xDB


// This crashes DOORS
DBE fnAddTab(DB xDB) {
void fnDoNothing(DBE xTab) {}
string options[] = {"One","Two","Three"}
DBE xTab = tab(xDB,options,400,200,fnDoNothing)
return xTab
}
DBE fnAddText(DB xDB) {
string xLabel = "This is some sample text"
string xInitial = "This is a bunch of meaningless text."
DBE xText = text(xDB,xLabel,xInitial,400,200,false)
return xText
}
DB xDB = centered "Sample"
DBE xTab = fnAddTab(xDB)
DBE xText = fnAddText(xDB)
show xDB


// This works again (define global string arrays)
string options[] = {"One","Two","Three"}

DBE fnAddTab(DB xDB) {
void fnDoNothing(DBE xTab) {}
DBE xTab = tab(xDB,options,400,200,fnDoNothing)
return xTab
}
DBE fnAddText(DB xDB) {
string xLabel = "This is some sample text"
string xInitial = "This is a bunch of meaningless text."
DBE xText = text(xDB,xLabel,xInitial,400,200,false)
return xText
}
DB xDB = centered "Sample"
DBE xTab = fnAddTab(xDB)
DBE xText = fnAddText(xDB)
show xDB


So, I have a very large dialog box, with many DBEs that require string arrays (tab strips, choice, radio, check, etc.). I've tried to use good programming practice by breaking up my code into functions. However, you cannot define string arrays locally without quickly running into problems. This means you must define all string arrays globably, which is also not good programming practice.

I submitted a DOORS trouble ticket a while ago about a similar issue and was told that DXL does not properly pass arrays back and forth between functions. Something about how once you pass the string array back from the function, that memory space is no longer protected and will get written over by other parts of your program. That's why, in the scripts above, the first one works, the second one is corrupted, and the third one completely crashed DOORS. I was hoping I might be able to get around this problem by defining these string arrays in-line in the function definitions. Oh well.
Report this to a Moderator Report this to a Moderator
 23-Jan-2008 16:08
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Yes string arrays that are used for DBEs need to be global since it needs to be accessed outside of the function.

I declare them as "const" to maintain good programming practice.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 23-Jan-2008 17:25
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

To clarify, the TAB and other DBEs store the address of the array when defined, and go to that address is consulted when the Dialog is 'realized'. If the array is defined in the local function that defines the DBE, then that area of the stack is invalid at the time the dialog is Realized, and you experience your corruption problem. You will probably have the same problem if you were able to insert a constant array into the TAB command.

Thus, these array's regrettably need to be defined globally so they are not subject to whims of the Stack.

- Louie
Report this to a Moderator Report this to a Moderator
 23-Jan-2008 18:40
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Sorry Louie. I meant I define them as "const" but globally. So they can't be modified.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 24-Jan-2008 14:38
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

The keyword const is useful for documenting your code but does not actually create a constant. Values can be modified.

// prints out 2 and 3.
const int i = 2
print i "\n"
i = 3
print i "\n"


I always use const and use a naming convention for "constants" which is all uppercase letters. This way I know to treat them as constants.

-------------------------
Tony Goodman
http://www.smartdxl.com

Edited: 24-Jan-2008 at 14:39 by Tony Goodman
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 0 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 0 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.