![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
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 |
![]() |
![]()
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
I think it better all the way around if one simply 'accepts' a particular DXL anomaly rather than try to 'rationally explain' it.
|
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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..... |
|
![]() |
|
![]() |
|
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
|
|
![]() |
|
![]() |
|
Since all the formatting got lost, lets try showing it in a code window so its more readable.
|
|
![]() |
|
![]() |
|
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 ![]() |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
What's wrong with this code?
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.