[an error occurred while processing this directive]
Думаю, что таки да., обязан (+)
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено ReAl 17 апреля 2006 г. 15:23
В ответ на: судя по всему нет, т.к. он ничего не знает о side effect данного чтения, а результат ему не нужен. В стандарте С прямого упоминания не нашел =( отправлено -=DASM=- 17 апреля 2006 г. 00:11


some_variable

Это выражение? выражение. evaluation ему надобно сделать? Надобно.
Дальше вступает в работу оптимизатор и итеративно выбрасывает то, что не нужно никому. И делать от это может до тех пор, пока не упрётся в возможные побочные эффекты - и тут он должен остановиться, чтобы не нарушать работу программы.
Т.е. - всё, что написано - должно быть сделано. Оптимизатор имеет право не делать до тех пор, пока это не приводит к различиям в "формально сделано как написано" и "делается после оптимизации".
Никого же не удивляет, что

int some_func(void);
:
:
some_func(); // без использования возвращнного значения где-либо

вызов some_func() не выбрасывается. А не выбрасывается он только потому, что функция может иметь неизвестный компилятору побочный эффект. Так вот с volatile-переменной то же самое.

Ещё пример:


volatile int a, b;
void foo(void) { (void)(a+b); }

Компилятор обязан сгенерировать чтение a и b, но вот уже их суммирование делать не обязан.

Выделение большими буквами ниже - моё

ISO/IEC 9899:1999 (E)
5.1.2.3 Program execution

1 The semantic descriptions in this International Standard describe the behavior of an
abstract machine in which issues of optimization are irrelevant.

2 Accessing a volatile object, modifying an object, modifying a file, or calling a function
that does any of those operations are all side effects,11) which are changes in the state of
the execution environment. Evaluation of an expression may produce side effects. At
certain specified points in the execution sequence called sequence points, all side effects
of previous evaluations shall be complete and no side effects of subsequent evaluations
shall have taken place. (A summary of the sequence points is given in annex C.)

3 In the abstract machine, all expressions are evaluated as specified by the semantics. An
actual implementation need not evaluate part of an expression IF IT CAN DEDUCE that its
VALUE IS NOT USED and that NO NEEDED SIDE EFFECTS are produced (including any caused by
calling a function or accessing a volatile object).

8 EXAMPLE 1 An implementation might define a one-to-one correspondence between abstract and actual
semantics: at every sequence point, the values of the actual objects would agree with those specified by the
abstract semantics. The keyword volatile would then be redundant.
9 Alternatively, an implementation might perform various optimizations within each translation unit, such
that the actual semantics would agree with the abstract semantics only when making function calls across
translation unit boundaries. In such an implementation, at the time of each function entry and function
return where the calling function and the called function are in different translation units, the values of all
externally linked objects and of all objects accessible via pointers therein would agree with the abstract
semantics. Furthermore, at the time of each such function entry the values of the parameters of the called
function and of all objects accessible via pointers therein would agree with the abstract semantics. In this
type of implementation, objects referred to by interrupt service routines activated by the signal function
would require explicit specification of volatile storage, as well as other implementation-defined
restrictions.

Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 
NoIX ключ Запомнить

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание

E-mail: info@telesys.ru