AXForum  
Go Back   AXForum > Microsoft Dynamics AX > DAX: Программирование
All
Forgotten Your Password?
Register Forum Rules FAQ Members List Today's Posts Search

 
 
Thread Tools Search this Thread Display Modes
Old 26.07.2006, 12:37   #1  
Buba is offline
Buba
Участник
 
90 / 10 (1) +
Join Date: 24.04.2003
Location: Томск
Делюсь опытом (вероятно с этим уже кто-либо сталкивался).

Ниже приведен код, в котором логическая формула E = a && (b || c && d)
(в Axapta 3.0 Professional SP3) вопреки ожиданиям быть TRUE принимает значение FALSE.

И только в таком исполнении E = a && (b || (c && d)) ожидания оправдываются.

Очень мило, особенно если логика ветвистая и от нее зависит не видимость или невидимость кнопок,
а, например, количество и содержание проводок по мудреной операции.

Самое главное - не мудрить!
А также не надеяться на фундаментальные правила.

Code:
static void Job106(Args _args)
{
	boolean a, b, c, d, E;

	a = true;
	b = true;
	c = false;
	d = false;

	E = a && (b || c && d);

	print a;
	print b;
	print c;
	print d;
	print E;
	pause;
}
Old 27.07.2006, 03:11   #2  
gbelot is offline
gbelot
Участник
 
16 / 10 (1) +
Join Date: 20.06.2006
I am wondering why you think it is strange. Axapta just executes them in the order, and because '&&' and '||' are basically equal, they get executed like this:

1. B || C returns 'true'
2. 'true' && D returns 'false', because D is false
3. A && 'false' returns false.

As a good practice we always are trying to reinforce the expected order of operations with parenteses.
Old 27.07.2006, 06:07   #3  
Buba is offline
Buba
Участник
 
90 / 10 (1) +
Join Date: 24.04.2003
Location: Томск
Нет возражений, однако это первый язык в моей практике, в котором операции OR и AND имеют один и тот же приоритет.
Old 27.07.2006, 10:35   #4  
Ser_imported is offline
Ser_imported
Участник
 
5 / 10 (1) +
Join Date: 20.11.2003
к сожалению, это так..
Microsoft Axapta Developer's Guide \ Operators and Expressions \ Operator precedence

Quote:
logical operators (AND, OR)


&& and ||
In X++, && (logical AND) and || (logical OR) have the same precedence and are evaluated from left to right.

This means that

0&&0||1 == 1 while

1||0&&0 == 0
Old 09.11.2006, 00:32   #5  
yanik84 is offline
yanik84
Участник
 
3 / 10 (1) +
Join Date: 09.11.2006
это тоже самое что и с++
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Рейтинг@Mail.ru
All times are GMT +3. The time now is 02:04.
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Contacts E-mail, Advertising.