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: What's wrong with this code?
Topic Summary:
Created On: 7-Nov-2006 20:05
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.
 7-Nov-2006 20:05
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

I've been beating my head against the wall over this, for a while now. Can anybody tell me why the following won't work? Have I just forgotten something simple?


const bool DEBUG = true

if(DEBUG == true)
string hi = "hello"


It gives a syntax error on the "string hi..." line. It does it with other variable types also (I found it using a Stream). Does DXL have a rule against declaring new variables inside if statements? If I put curly brackets around it, there is no problem.....

Thanks,
Chris
Report this to a Moderator Report this to a Moderator
 7-Nov-2006 20:25
User is offline View Users Profile Print this message


ron lewis

Posts: 650
Joined: 20-Sep-2004

Declaring the string after the if would make the string 'hi' unusable because of the scope is within the if statement.

Putting braces around it would me that hi could be usuable with the block defined by the braces.
Report this to a Moderator Report this to a Moderator
 7-Nov-2006 20:52
User is offline View Users Profile Print this message


Pete Kowalski

Posts: 301
Joined: 7-Feb-2003

Also, you can write your "if" condition as follows. This means if condition is true execute the enclosed code.

-------------------------
pete.kowalski(at)motorola.com

Edited: 7-Nov-2006 at 23:18 by Pete Kowalski
Report this to a Moderator Report this to a Moderator
 8-Nov-2006 07:52
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

I'm guessing now, but could it be that the declaration and the assignment are effectively (as far as DXL is concerned) two separate statements that just happen to be combined into a signal declare-and-assign statement? If that were the case, then the declaration 'string hi' would be part of the 'if' clause, and the assigment 'hi = "hello"' would be outside the if, and thus invalid because there is no 'hi' to assign to.

One (inconclusive) way to test this might be to turn on auto-declare (assuming it's off!) and see whether you get the same result. If auto-declare is on, that doesn't mean I'm wrong, just not completely right .

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 8-Nov-2006 23:33
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

I think it better all the way around if one simply 'accepts' a particular DXL anomaly rather than try to 'rationally explain' it.
Report this to a Moderator Report this to a Moderator
 9-Nov-2006 08:31
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Louie, I agree. But we're engineers. Sometimes we just have to know WHY!

Chris, Ron's right. There's absolutely no point in doing what you're trying to do. Even if you put the braces around it, like Pete suggested (Snippet 1 in the window), what does it gain you? The variable is only available inside the braces, and there's only an assignment there. If you want to do more with the variable, you have to use the braces, or declare the variable outside and only assign as part of the 'if' (Snippet 2 in the window).

So the long and the short of it -- it really doesn't matter that it doesn't work, because if it did, you wouldn't be able to use it!

Paul.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 10-Nov-2006 00:34
User is offline View Users Profile Print this message


Chris Jones

Posts: 177
Joined: 1-Jul-2005

I get the same result with AutoDeclare on and off. But of course other statements work after an if, with no brackets (see snippet).

I hadn't thought of the fact that I wouldn't be able to see it later--which, come to think of it, explains some of the other errors I was getting. So, armed with that and with brackets, I can fix the script that had the problem in the first place. Things like this do kind of make me wonder, but I think Louie has something there with the "accepting things you can't do anything about" idea.....
Report this to a Moderator Report this to a Moderator
 10-Nov-2006 09:53
User is offline View Users Profile Print this message


Robert Swan

Posts: 86
Joined: 14-Apr-2005

On the DXL course it was stressed that an IF without {} only executes the next line So seems to me that the language syntax (at least this part) is:- IF Condition then StatementBlock where StatementBlock = Statement or StatementBlock = {StatementList} or StatementBlock ={DeclarationList StatementBlock} therefore IF Condition then Declaration is not a legal format. (I think that's what all the others said but slightly more formally
Report this to a Moderator Report this to a Moderator
 13-Nov-2006 08:50
User is offline View Users Profile Print this message


Robert Swan

Posts: 86
Joined: 14-Apr-2005

Since all the formatting got lost, lets try showing it in a code window so its more readable.
Report this to a Moderator Report this to a Moderator
 13-Nov-2006 13:47
User is offline View Users Profile Print this message


Antonio Norkus

Posts: 109
Joined: 28-Jun-2003

I don't know WHY it's illegal, but I can't think of a single case for where you could make use of it if it was legal.

Therefore, it may be presuming that you didn't really want to declare it there, and presents you with an error.

To me, that seems like a sensible thing to do
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 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 2 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.