Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Баг в IAR
Форум разработчиков электроники ELECTRONIX.ru > Микроконтроллеры (MCs) > ARM
Nikola Kirov
Если сделат следущее
1) Сделаите проект.
2) Добавите в .c фаил

#define X 5
#define Y X+1
#undef X
#define X Y
#if X != 6
#error
#endif

3) прекомпилируйте...

Етот проект уже невозможно скомпилироват sad.gif

Кажется что проблем в #error . А ето думаю из стандарта и должно работат.
zltigo
Цитата(Nikola Kirov @ Dec 17 2006, 17:57) *
#define X 5
#define Y X+1
#undef X
#define X Y
#if X != 6
#error
#endif

Это все эквивалентно:
Код
#if X+1 != 6
#error
#endif

Причем X не определен.
Естественно должно вызвать как минимум выход на #error а как максимум еще сообщение о том,что X не
определен.
Никаких "багов".
Nikola Kirov
Сделай все как описано.
Увидиш smile.gif

В последней версии IAR-a получается всегда smile.gif
Alex03
Я бы сказал что эквивалент:
Код
#define Y X+1
#define X Y
#if X != 6
#error
#endif


Цитата(zltigo @ Dec 18 2006, 01:00) *
Причем X не определен.


А тут интересный момент, X какбы и определён и не определён. smile.gif

Цитата
... а как максимум еще сообщение о том,что X не определен.

Именно тут его сообщения не будет (по крайней мере в GCC) ибо:
Цитата
Identifiers that are not macros, which are all considered to be the number zero. This allows you to write #if MACRO instead of #ifdef MACRO, if you know that MACRO, when defined, will always have a nonzero value. Function-like macros used without their function call parentheses are also treated as zero.

Таким образом "#if X != 6" разворачивается в
Код
#if 0 + 1 != 6

В чём можно убедиться заменив 6 на 1

Цитата(Nikola Kirov @ Dec 17 2006, 20:57) *
Етот проект уже невозможно скомпилироват sad.gif
Кажется что проблем в #error . А ето думаю из стандарта и должно работат.

Nikola Kirov А чего хотелось получить то?

хелп на GCC препроцессор говорит ишо такое:
Цитата
Self-Referential Macros

A self-referential macro is one whose name appears in its definition. Recall that all macro definitions are rescanned for more macros to replace. If the self-reference were considered a use of the macro, it would produce an infinitely large expansion. To prevent this, the self-reference is not considered a macro call. It is passed into the preprocessor output unchanged. Let's consider an example:
#define foo (4 + foo)


where foo is also a variable in your program.

Following the ordinary rules, each reference to foo will expand into (4 + foo); then this will be rescanned and will expand into (4 + (4 + foo)); and so on until the computer runs out of memory.

The self-reference rule cuts this process short after one step, at (4 + foo). Therefore, this macro definition has the possibly useful effect of causing the program to add 4 to the value of foo wherever foo is referred to.

In most cases, it is a bad idea to take advantage of this feature. A person reading the program who sees that foo is a variable will not expect that it is a macro as well. The reader will come across the identifier foo in the program and think its value should be that of the variable foo, whereas in fact the value is four greater.

One common, useful use of self-reference is to create a macro which expands to itself. If you write
#define EPERM EPERM


then the macro EPERM expands to EPERM. Effectively, it is left alone by the preprocessor whenever it's used in running text. You can tell that it's a macro with #ifdef. You might do this if you want to define numeric constants with an enum, but have #ifdef be true for each constant.

If a macro x expands to use a macro y, and the expansion of y refers to the macro x, that is an indirect self-reference of x. x is not expanded in this case either. Thus, if we have
#define x (4 + y)
#define y (2 * x)


then x and y expand as follows:
x ==> (4 + y)
==> (4 + (2 * x))

y ==> (2 * x)
==> (2 * (4 + y))


Each macro is expanded when it appears in the definition of the other macro, but not when it indirectly appears in its own definition.
zltigo
Цитата(Nikola Kirov @ Dec 17 2006, 22:03) *
Сделай все как описано.
Увидиш smile.gif

Что я увижу? Предупреждение о неопределенности X? Выход на #error, поскольку 6 не равно 1?
Совершенно правильно - я это увижу и выход на #error и есть совершенно правильное поведение
препроцессора а не баг.


Цитата
Именно тут его сообщения не будет (по крайней мере в GCC) ибо:

Identifiers that are not macros, which are all considered to be the number zero. This allows you to write #if MACRO instead of #ifdef MACRO, if you know that MACRO, when defined, will always have a nonzero value. Function-like macros used without their function call parentheses are also treated as zero.

Некоторые компиляторы, и в том числе IAR, выдают Warning или Note или Remark именно о том, что
неопределенный MACRO был принят равным 0.
Nikola Kirov
Как вижу никто не пробовал как написано. smile.gif

Как интерпретируется ето совсем ясно.
Баг в то что после первой компиляции проект вообще не может компилится. Можно и убрат потом

#define Y X+1
#define X Y
#if X != 6
#error
#endif

но уже проект не компилируется smile.gif.
zltigo
Цитата(Nikola Kirov @ Dec 18 2006, 13:47) *
Как вижу никто не пробовал как написано. smile.gif

Сейчас пробовал в IAR 4.41A
Цитата
но уже проект не компилируется smile.gif.

Ошибка и Remark выдаются.
Если все убрать - все без проблем.
Nikola Kirov
Станно. Тут попробовали на несколко компютеров.
Резултат один и тоже.

Проект не компилится после ето.

я лично пробовал при
EWARM-EV-WEB-441A.exe
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Invision Power Board © 2001-2025 Invision Power Services, Inc.