Changeset ed79428
- Timestamp:
- Dec 12, 2023, 11:29:06 AM (12 months ago)
- Branches:
- master
- Children:
- 7972603
- Parents:
- cd79053
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/background.tex
rcd79053 red79428 40 40 41 41 TODO: typeset 42 \lstinputlisting[language=C, firstline=13, lastline=56]{bkgd-c-tyerr.c}42 %\lstinputlisting[language=C, firstline=13, lastline=56]{bkgd-c-tyerr.c} 43 43 44 44 … … 48 48 49 49 TODO: typeset 50 \lstinputlisting[language=C, firstline=35, lastline=116]{bkgd-carray-arrty.c}50 %\lstinputlisting[language=C, firstline=35, lastline=116]{bkgd-carray-arrty.c} 51 51 52 52 My contribution is enabled by recognizing … … 176 176 177 177 TODO: typeset 178 \lstinputlisting[language=C, firstline=4, lastline=26]{bkgd-carray-decay.c}178 %\lstinputlisting[language=C, firstline=4, lastline=26]{bkgd-carray-decay.c} 179 179 180 180 … … 229 229 the parameter's type becomes a type that I summarize as being the array-decayed type. 230 230 The respective handlings of the following two parameter spellings shows that the array-spelled one is really, like the other, a pointer. 231 \lstinputlisting[language=C, firstline=40, lastline=44]{bkgd-carray-decay.c}231 %\lstinputlisting[language=C, firstline=40, lastline=44]{bkgd-carray-decay.c} 232 232 As the @sizeof(x)@ meaning changed, compared with when run on a similarly-spelled local variariable declaration, 233 233 GCC also gives this code the warning: ```sizeof' on array function parameter `x' will return size of `float *'.'' 234 234 235 235 The caller of such a function is left with the reality that a pointer parameter is a pointer, no matter how it's spelled: 236 \lstinputlisting[language=C, firstline=60, lastline=63]{bkgd-carray-decay.c}236 %\lstinputlisting[language=C, firstline=60, lastline=63]{bkgd-carray-decay.c} 237 237 This fragment gives no warnings. 238 238 … … 240 240 Note the opposite meaning of this spelling now, compared with its use in local variable declarations. 241 241 This point of confusion is illustrated in: 242 \lstinputlisting[language=C, firstline=80, lastline=87]{bkgd-carray-decay.c}242 %\lstinputlisting[language=C, firstline=80, lastline=87]{bkgd-carray-decay.c} 243 243 The basic two meanings, with a syntactic difference helping to distinguish, 244 244 are illustrated in the declarations of @ca@ vs.\ @cp@, … … 259 259 Pointer decay does not affect pointer-to-array types, because these are already pointers, not arrays. 260 260 As a result, a function with a pointer-to-array parameter sees the parameter exactly as the caller does: 261 \lstinputlisting[language=C, firstline=100, lastline=110]{bkgd-carray-decay.c}261 %\lstinputlisting[language=C, firstline=100, lastline=110]{bkgd-carray-decay.c} 262 262 263 263 … … 414 414 which type information associated with a polymorphic return type 415 415 replaces @malloc@'s use of programmer-supplied size information. 416 \begin{lst inline}416 \begin{lstlisting} 417 417 // C, library 418 418 void * malloc( size_t ); … … 426 426 tm * el2 = alloc(); 427 427 tm (*ar2)[10] = alloc(); 428 \end{lst inline}428 \end{lstlisting} 429 429 The alloc polymorphic return compiles into a hidden parameter, which receives a compiler-generated argument. 430 430 This compiler's argument generation uses type information from the left-hand side of the initialization to obtain the intended type. … … 436 436 In the last example, the choice of ``pointer to array'' @ar2@ breaks a parallel with @ar1@. 437 437 They are not subscripted in the same way. 438 \begin{lst inline}438 \begin{lstlisting} 439 439 ar1[5]; 440 440 (*ar2)[5]; 441 \end{lst inline}441 \end{lstlisting} 442 442 Using ``reference to array'' works at resolving this issue. TODO: discuss connection with Doug-Lea \CC proposal. 443 \begin{lst inline}443 \begin{lstlisting} 444 444 tm (&ar3)[10] = *alloc(); 445 445 ar3[5]; 446 \end{lst inline}446 \end{lstlisting} 447 447 The implicit size communication to @alloc@ still works in the same ways as for @ar2@. 448 448 449 Using proper array types (@ar2@ and @ar3@) addresses a concern about using raw element pointers (@ar1 ), albeit a theoretical one.449 Using proper array types (@ar2@ and @ar3@) addresses a concern about using raw element pointers (@ar1@), albeit a theoretical one. 450 450 TODO xref C standard does not claim that @ar1@ may be subscripted, 451 451 because no stage of interpreting the construction of @ar1@ has it be that ``there is an \emph{array object} here.'' … … 453 453 where the type requested is an array, making the result, much more obviously, an array object. 454 454 455 The ``reference to array'' type has its sore spots too. TODO see also dimexpr-match-c/REFPARAM_CALL (under TRY_BUG_1)455 The ``reference to array'' type has its sore spots too. TODO see also @dimexpr-match-c/REFPARAM_CALL (under TRY_BUG_1)@ 456 456 457 457
Note: See TracChangeset
for help on using the changeset viewer.