Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Strings are a fundamental concept in software engineering, but they are not a built-in type in C. Null-terminated byte strings (NTBS) consist of a contiguous sequence of characters terminated by and including the first null character, and are supported in C as the format used for string literals. The C programming language supports the following types of null-terminated byte strings: single-byte character strings, multibyte character strings, and wide character strings. Single-byte and multibyte character strings are both described as null-terminated byte strings, which are also referred to as "narrow character strings".

A pointer to a singlenull-terminated byte or multibyte character string points to its initial character. The length of the string is the number of bytes preceding the null character, and the value of the string is the sequence of the values of the contained characters, in order.

A wide string is a contiguous sequence of wide characters (of type wchar_t) terminated by and including the first null wide character. A pointer to a wide string points to its initial (lowest addressed) wide character. The length of a wide string is the number of wide characters preceding the null wide character, and the value of a wide string is the sequence of code values of the contained wide characters, in order.

...

  • The type of each element of a string literal.
  • Used for character data from a limited character set (where signedness has little meaning) as opposed to integer data.

wide characters wchar_t

  • Used for natural-language character data.

int

  • Used for data that could be either EOF (a negative value) or character data interpreted as unsigned char and then converted to int.   ThereforeAs a result, returned by fgetc(), getc(), getchar(), and ungetc().   Also, accepted by the character handling functions from <ctype.h>, because they might be passed the result of fgetc() et al, etc.
  • The type of a character constant.   Its value is that of a plain char converted to int.

...

Understanding how to represent characters and character strings can eliminate many common programming errors that lead to software vulnerabilities.

...