5. В Паскале строки представляются массивом символов; при этом размер массива хранится в отдельной (служебной) области. При этом программа в каждый момент времени «знает» о размере строки, и операции добавления символов в конец, копирования и получения размера строки выполняются достаточно быстро.
В Си используются строки с завершающим нулевым символом, и строка хранится как последовательность байтов от начала до конца.
При этом конкатенация происходит медленно, во время нее каждый символ копируется отдельно.
6.4.5 String literals
Syntax
1
(...)
Description
2
(...)
Semantics
4
In translation phase 6, the multibyte character sequences specified by any sequence of
adjacent character and wide string literal tokens are concatenated into a single multibyte
character sequence. If any of the tokens are wide string literal tokens, the resulting
multibyte character sequence is treated as a wide string literal; otherwise, it is treated as a
character string literal.
5
In translation phase 7, a byte or code of value zero is appended to each multibyte
character sequence that results from a string literal or literals.68) The multibyte character
sequence is then used to initialize an array of static storage duration and length just
sufficient to contain the sequence. For character string literals, the array elements have
type char, and are initialized with the individual bytes of the multibyte character
sequence; for wide string literals, the array elements have type wchar_t, and are
initialized with the sequence of wide characters corresponding to the multibyte character
sequence, as defined by the mbstowcs function with an implementation-defined current
locale. The value of a string literal containing a multibyte character or escape sequence
not represented in the execution character set is implementation-defined.
6
It is unspecified whether these arrays are distinct provided their elements have the
appropriate values. If the program attempts to modify such an array, the behavior is
undefined.
7
EXAMPLE
(...)
7. Library
7.1 Introduction
7.1.1 Definitions of terms
1
A string is a contiguous sequence of characters terminated by and including the first null
character. The term multibyte string is sometimes used instead to emphasize special
processing given to multibyte characters contained in the string or to avoid confusion
with a wide string. A pointer to a string is a pointer to its initial (lowest addressed)
character. The length of a string is the number of bytes preceding the null character and
the value of a string is the sequence of the values of the contained characters, in order.
В каком алгоритмическом языке — в Паскале или в Си — операция конкатенации (соединения) строк реализуется более эффективно?
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.