Changeset c4024b46 for doc/theses/mike_brooks_MMath
- Timestamp:
- Apr 10, 2024, 1:10:14 PM (8 months ago)
- Branches:
- master
- Children:
- 21e6da5, ab780e6
- Parents:
- 0554c1a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/background.tex
r0554c1a rc4024b46 236 236 \lstinput{12-16}{bkgd-carray-decay.c} 237 237 As the @sizeof(x)@ meaning changed, compared with when run on a similarly-spelled local variable declaration, 238 GCCalso gives this code the warning for the first assertion:238 @gcc@ also gives this code the warning for the first assertion: 239 239 \begin{cfa} 240 240 warning: 'sizeof' on array function parameter 'x' will return size of 'float *' … … 321 321 This arrangement allocates @n@ elements on the @main@ stack frame for @ar@, called a \newterm{variable length array} (VLA), as well as 10 elements in the same stack frame for @b@. 322 322 The variable-sized allocation of @ar@ is provided by the @alloca@ routine, which bumps the stack pointer. 323 Note, the C standard supports VLAs , but the \CC standard does not;323 Note, the C standard supports VLAs~\cite[\S~6.7.6.2.4]{C11} as a conditional feature, but the \CC standard does not; 324 324 both @gcc@ and @g++@ support VLAs. 325 325 As well, there is misinformation about VLAs, \eg VLAs cause stack failures or are inefficient. 326 326 VLAs exist as far back as Algol W~\cite[\S~5.2]{AlgolW} and are a sound and efficient data type. 327 327 328 In situations where the stack size has a small bound (coroutines or user-level threads), unbounded VLAs can overflow the stack so a heap allocation is used. 328 For high-performance applications, the stack size can be fixed and small (coroutines or user-level threads). 329 Here, VLAs can overflow the stack, so a heap allocation is used. 329 330 \begin{cfa} 330 331 float * ax1 = malloc( sizeof( float[n] ) ); … … 393 394 \section{Linked List} 394 395 396 Linked-lists are blocks of storage connected using one or more pointers. 397 The storage block is logically divided into data and links (pointers), where the links are the only component used by the list structure. 398 Since the data is opaque, list structures are often polymorphic over the data, which is normally homogeneous. 399 395 400 396 401 \section{String} 402 403 A string is a logical sequence of symbols, where the form of the symbols can vary significantly: 7/8-bit characters (ASCII/Latin-1), or 2/4/8-byte (UNICODE) characters/symbols or variable length (UTF-8/16/32) characters. 404 A string can be read left-to-right, right-to-left, top-to-bottom, and have stacked elements (Arabic). 405 406 An integer character constant is a sequence of one or more multibyte characters enclosed in single-quotes, as in @'x'@. 407 A wide character constant is the same, except prefixed by the letter @L@, @u@, or @U@. 408 With a few exceptions detailed later, the elements of the sequence are any members of the source character set; 409 they are mapped in an implementation-defined manner to members of the execution character set. 410 411 A C character-string literal is a sequence of zero or more multibyte characters enclosed in double-quotes, as in @"xyz"@. 412 A UTF-8 string literal is the same, except prefixed by @u8@. 413 A wide string literal is the same, except prefixed by the letter @L@, @u@, or @U@. 414 415 For UTF-8 string literals, the array elements have type @char@, and are initialized with the characters of the multibyte character sequence, as encoded in UTF-8. 416 For wide string literals prefixed by the letter @L@, 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. 417 For wide string literals prefixed by the letter @u@ or @U@, the array elements have type @char16_t@ or @char32_t@, respectively, and are initialized with the sequence of wide characters corresponding to the multibyte character sequence, as defined by successive calls to the @mbrtoc16@, or @mbrtoc32@ function as appropriate for its type, with an implementation-defined current locale. 418 The value of a string literal containing a multibyte character or escape sequence not represented in the executioncharacter set is implementation-defined. 419 420 421 Another bad C design decision is to have null-terminated strings rather than maintaining a separate string length. 422 \begin{quote} 423 Technically, a string is an array whose elements are single characters. 424 The compiler automatically places the null character @\0@ at the end of each such string, so programs can conveniently find the end. 425 This representation means that there is no real limit to how long a string can be, but programs have to scan one completely to determine its length. 426 \end{quote}
Note: See TracChangeset
for help on using the changeset viewer.