Changeset 32490deb


Ignore:
Timestamp:
Jan 31, 2024, 6:40:25 PM (21 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
496ffc17
Parents:
c75b30a (diff), e71b09a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
22 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.sty

    rc75b30a r32490deb  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Jan 14 12:28:26 2024
    14 %% Update Count     : 631
     13%% Last Modified On : Sun Jan 21 13:17:48 2024
     14%% Update Count     : 633
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    270270\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
    271271\newlength{\columnposn}
    272 \setlength{\gcolumnposn}{2.75in}
     272\setlength{\gcolumnposn}{3in}
    273273\setlength{\columnposn}{\gcolumnposn}
    274274\newcommand{\setgcolumn}[1]{\global\gcolumnposn=#1\global\columnposn=\gcolumnposn}
  • doc/LaTeXmacros/common.tex

    rc75b30a r32490deb  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Jan 14 17:59:02 2024
    14 %% Update Count     : 592
     13%% Last Modified On : Wed Jan 24 08:43:57 2024
     14%% Update Count     : 593
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    273273\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
    274274\newlength{\columnposn}
    275 \setlength{\gcolumnposn}{2.75in}
     275\setlength{\gcolumnposn}{3in}
    276276\setlength{\columnposn}{\gcolumnposn}
    277277\newcommand{\setgcolumn}[1]{\global\gcolumnposn=#1\global\columnposn=\gcolumnposn}
  • doc/bibliography/pl.bib

    rc75b30a r32490deb  
    219219    title       = {Actor Benchmarks},
    220220    author      = {Peter A. Buhr and Colby A. Parsons},
    221     howpublished= {\href{https://github.com/pabuhr/ActorExperiments}{https://\-github.com/\-pabuhr/\-ActorExperiments}},
     221    howpublished= {\url{https://github.com/pabuhr/ActorExperiments}},
    222222    year        = 2022,
    223223}
     
    296296    contributer = {pabuhr@plg},
    297297    author      = {Ada16},
    298     title       = {Ada Reference Manual  ISO/IEC 8652:2012(E) with COR.1:2016},
     298    title       = {Ada Reference Manual ISO/IEC 8652:2012(E) with COR.1:2016},
    299299    edition     = {3rd with Technical Corrigendum 1 for Ada 2012},
    300300    organization= {AXE Consultants},
     
    416416    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    417417    optnote     = {\textsf{http://uwspace.uwaterloo.ca/\-bitstream/10012/\-5751\-/1/Krischer\_Roy.pdf}},
    418     note        = {\href{http://uwspace.uwaterloo.ca/bitstream/10012/5751/1/Krischer_Roy.pdf}{http://uwspace.uwaterloo.ca/\-bitstream/10012/\-5751\-/1/Krischer\_Roy.pdf}},
     418    note        = {\url{http://uwspace.uwaterloo.ca/bitstream/10012/5751/1/Krischer_Roy.pdf}},
    419419}
    420420
     
    430430    number      = 5,
    431431    pages       = {1005-1042},
    432     optnote     = {\href{https://onlinelibrary.wiley.com/doi/10.1002/spe.2925}{https://\-onlinelibrary.wiley.com/\-doi/\-10.1002/\-spe.2925}},
     432    optnote     = {\url{https://onlinelibrary.wiley.com/doi/10.1002/spe.2925}},
    433433}
    434434
     
    761761    pages       = {145-160},
    762762    publisher   = {{USENIX} Association},
    763     note        = {\href{https://www.usenix.org/conference/osdi18/presentation/qin}{https://\-www.usenix.org/\-conference/\-osdi18/\-presentation/\-qin}},
     763    note        = {\url{https://www.usenix.org/conference/osdi18/presentation/qin}},
    764764}
    765765
     
    839839    title       = {Async Await},
    840840    author      = {{WikipediA}},
    841     howpublished= {\href{https://en.wikipedia.org/wiki/Async/await}{https://\-en.wikipedia.org/\-wiki/\-Async/\-await}},
     841    howpublished= {\url{https://en.wikipedia.org/wiki/Async/await}},
    842842    year        = 2022,
    843843}
     
    928928    institution = {Carnegie Mellon University},
    929929    address     = {California Institute of Technology, Pasadena, CA, USA},
    930     note        = {\href{http://www.cs.cmu.edu/~acw/15740/paper.pdf}{http://\-www.cs.cmu.edu/\-$\sim$acw/\-15740/\-paper.pdf}, Accessed May 2014},
     930    note        = {\url{http://www.cs.cmu.edu/~acw/15740/paper.pdf}},
    931931    year        = 2009,
    932932}
     
    10341034    title       = {Boost Coroutine Library},
    10351035    year        = 2015,
    1036     howpublished= {\href{http://www.boost.org/doc/libs/1_61_0/libs/coroutine/doc/html/index.html}
    1037                   {http://www.boost.org/\-doc/\-libs/1\_61\_0/\-libs/\-coroutine/\-doc/\-html/\-index.html}},
     1036    howpublished= {\url{http://www.boost.org/doc/libs/1_61_0/libs/coroutine/doc/html/index.html}},
    10381037}
    10391038
     
    10441043    title       = {Boost Thread Library},
    10451044    year        = 2015,
    1046     howpublished= {\href{https://www.boost.org/doc/libs/1_61_0/doc/html/thread.html}
    1047                   {https://\-www.boost.org/\-doc/\-libs/\-1\_61\_0/\-doc/\-html/\-thread.html}},
     1045    howpublished= {\url{https://www.boost.org/doc/libs/1_61_0/doc/html/thread.html}},
    10481046}
    10491047
     
    10561054    month       = oct,
    10571055    type        = {Diplomarbeit},
    1058     note        = {\href{https://plg.uwaterloo.ca/~usystem/theses/KrischerThesis.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-theses/\-KrischerThesis.pdf}},
     1056    note        = {\url{https://plg.uwaterloo.ca/~usystem/theses/KrischerThesis.pdf}},
    10591057}
    10601058
     
    11481146    address     = {Geneva, Switzerland},
    11491147    year        = 1999,
    1150     note        = {\href{https://webstore.ansi.org/Standards/INCITS/INCITSISOIEC98991999R2005}{https://webstore.ansi.org/\-Standards/\-INCITS/\-INCITSISOIEC98991999R2005}},
     1148    note        = {\url{https://webstore.ansi.org/Standards/INCITS/INCITSISOIEC98991999R2005}},
    11511149}
    11521150
     
    11601158    address     = {Geneva, Switzerland},
    11611159    year        = 2012,
    1162     note        = {\href{https://www.iso.org/standard/57853.html}{https://\-www.iso.org/\-standard/\-57853.html}},
     1160    note        = {\url{https://www.iso.org/standard/57853.html}},
    11631161}
    11641162
     
    11711169    address     = {Geneva, Switzerland},
    11721170    year        = 2015,
    1173     note        = {\href{https://www.iso.org/standard/64031.html}{https://\-www.iso.org/\-standard/\-64031.html}},
     1171    note        = {\url{https://www.iso.org/standard/64031.html}},
    11741172}
    11751173
     
    11981196    month       = aug,
    11991197    year        = {2020},
    1200     note        = {\href{https://cforall.uwaterloo.ca/doc/Fangren_Yu_Report_S20.pdf}{https://\-cforall.uwaterloo.ca/\-doc/\-Fangren\_Yu\_Report\_S20.pdf}},
     1198    note        = {\url{https://cforall.uwaterloo.ca/doc/Fangren_Yu_Report_S20.pdf}},
    12011199}
    12021200
     
    12121210    year        = 2018,
    12131211    pages       = {2111-2146},
    1214     optnote     = {\href{http://dx.doi.org/10.1002/spe.2624}{http://\-dx.doi.org/\-10.1002/\-spe.2624}},
     1212    optnote     = {\url{http://dx.doi.org/10.1002/spe.2624}},
    12151213}
    12161214
     
    12191217    key         = {Cforall Benchmarks},
    12201218    author      = {{\textsf{C}{$\mathbf{\forall}$} Benchmarks}},
    1221     howpublished= {\href{https://github.com/cforall/ConcurrentBenchmarks_SPE20}{https://\-github.com/\-cforall/\-ConcurrentBenchmarks\_SPE20}},
     1219    howpublished= {\url{https://github.com/cforall/ConcurrentBenchmarks_SPE20}},
    12221220}
    12231221
     
    12261224    key         = {Cforall},
    12271225    author      = {{\textsf{C}{$\mathbf{\forall}$} Features}},
    1228     howpublished= {\href{https://plg.uwaterloo.ca/~cforall/features}{https://\-plg.uwaterloo.ca/\-$\sim$cforall/\-features}},
     1226    howpublished= {\url{https://plg.uwaterloo.ca/~cforall/features}},
    12291227}
    12301228
     
    12451243    title       = {\textsf{C}$\mathbf{\forall}$ Stack Evaluation Programs},
    12461244    year        = 2018,
    1247     howpublished= {\href{https://cforall.uwaterloo.ca/CFAStackEvaluation.zip}{https://cforall.uwaterloo.ca/\-CFAStackEvaluation.zip}},
     1245    howpublished= {\url{https://cforall.uwaterloo.ca/CFAStackEvaluation.zip}},
    12481246}
    12491247
     
    12561254    year        = 2004,
    12571255    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    1258     note        = {\href{http://plg.uwaterloo.ca/theses/EstevesThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-EstevesThesis.pdf}},
     1256    note        = {\url{http://plg.uwaterloo.ca/theses/EstevesThesis.pdf}},
    12591257}
    12601258
     
    12661264    year        = 2019,
    12671265    optaddress  = {Waterloo, Ontario, Canada, N2L 3G1},
    1268     note        = {\href{https://uwspace.uwaterloo.ca/handle/10012/14584}{https://\-uwspace.uwaterloo.ca/\-handle/\-10012/\-14584}},
     1266    note        = {\url{https://uwspace.uwaterloo.ca/handle/10012/14584}},
    12691267}
    12701268
     
    14231421    month       = oct,
    14241422    year        = 2001,
    1425     note        = {\href{http://plg.uwaterloo.ca/~cforall/cfa.ps}{http://\-plg.uwaterloo.ca/\-$\sim$cforall/\-cfa.ps}},
     1423    note        = {\url{http://plg.uwaterloo.ca/~cforall/cfa.ps}},
    14261424}
    14271425
     
    14611459    contributer = {a3moss@uwaterloo.ca},
    14621460    title       = {Clang: a {C} language family frontend for {LLVM}},
    1463     howpublished= {\href{https://clang.llvm.org/}{https://\-clang.llvm.org/}}
     1461    howpublished= {\url{https://clang.llvm.org/}}
    14641462}
    14651463
     
    15271525    address     = {Geneva, Switzerland},
    15281526    year        = 2014,
    1529     note        = {\href{https://www.iso.org/standard/51416.html}{https://\-www.iso.org/\-standard/\-51416.html}},
     1527    note        = {\url{https://www.iso.org/standard/51416.html}},
    15301528}
    15311529
     
    16681666    publisher   = {Prentice-Hall},
    16691667    address     = {Upper Saddle River, NJ, USA},
    1670     note        = {\href{http://www.usingcsp.com/cspbook.pdf}{http://\-www.usingcsp.com/\-cspbook.pdf}},
     1668    note        = {\url{http://www.usingcsp.com/cspbook.pdf}},
    16711669}
    16721670
     
    17331731    month       = sep,
    17341732    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    1735     note        = {\href{http://plg.uwaterloo.ca/theses/MokThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-MokThesis.pdf}},
     1733    note        = {\url{http://plg.uwaterloo.ca/theses/MokThesis.pdf}},
    17361734}
    17371735
     
    18081806    author      = {Peter A. Buhr and David Dice and Wim H. Hesselink},
    18091807    title       = {concurrent-locking},
    1810     howpublished= {\href{https://github.com/pabuhr/concurrent-locking}{https://\-github.com/\-pabuhr/\-concurrent-locking}},
     1808    howpublished= {\url{https://github.com/pabuhr/concurrent-locking}},
    18111809}
    18121810
     
    19581956    year        = 2015,
    19591957    optaddress  = {Waterloo, Ontario, Canada, N2L 3G1},
    1960     note        = {\href{https://uwspace.uwaterloo.ca/handle/10012/10013}{https://\-uwspace.uwaterloo.ca/\-handle/\-10012/\-10013}},
     1958    note        = {\url{https://uwspace.uwaterloo.ca/handle/10012/10013}},
    19611959}
    19621960
     
    20982096    month       = oct,
    20992097    year        = 2010,
    2100     howpublished= {\href{https://www.airs.com/blog/archives/428}
    2101                   {https://www.airs.com/\-blog/\-archives/\-428}},
     2098    howpublished= {\url{https://www.airs.com/blog/archives/428}},
    21022099}
    21032100
     
    21102107    year        = 1992,
    21112108    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    2112     note        = {\href{http://plg.uwaterloo.ca/theses/DitchfieldThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-DitchfieldThesis.pdf}}
     2109    note        = {\url{http://plg.uwaterloo.ca/theses/DitchfieldThesis.pdf}}
    21132110}
    21142111
     
    21802177    author      = {Glen Ditchfield},
    21812178    title       = {Conversions for \textsf{C}$\mathbf{\forall}$},
    2182     note        = {\href{http://plg.uwaterloo.ca/~cforall/Conversions/index.html}{http://\-plg.uwaterloo.ca/\-$\sim$cforall/\-Conversions/\-index.html}},
     2179    note        = {\url{http://plg.uwaterloo.ca/~cforall/Conversions/index.html}},
    21832180    month       = {Nov},
    21842181    year        = {2002},
     
    22172214    year        = 2019,
    22182215    month       = feb,
    2219     howpublished= {\href{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0912r5.html}
    2220                   {http://\-www.open-std.org/\-jtc1/\-sc22/\-wg21/\-docs/\-papers/\-2019/p0912r5.html}},
     2216    howpublished= {\url{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0912r5.html}},
    22212217}
    22222218
     
    22292225    month       = jun,
    22302226    year        = 2022,
    2231     note        = {\href{https://en.cppreference.com/w/cpp/language/coroutines}{https://\-en.cppreference.com/\-w/\-cpp/\-language/\-coroutines}},
     2227    note        = {\url{https://en.cppreference.com/w/cpp/language/coroutines}},
    22322228}
    22332229
     
    22832279    title       = {CS343},
    22842280    year        = 2018,
    2285     howpublished= {\href{https://www.student.cs.uwaterloo.ca/~cs343}{https://\-www.student.cs.uwaterloo.ca/\-$\sim$cs343}},
     2281    howpublished= {\url{https://www.student.cs.uwaterloo.ca/~cs343}},
    22862282}
    22872283
     
    23092305    address     = {Vienna Virginia, U.S.A.},
    23102306    year        = 2016,
    2311     note        = {\href{http://dlang.org/spec/spec.html}{http://\-dlang.org/\-spec/\-spec.html}},
     2307    note        = {\url{http://dlang.org/spec/spec.html}},
    23122308}
    23132309
     
    27862782    author      = {Martin Odersky},
    27872783    title       = {Dotty},
    2788     howpublished= {\href{https://github.com/lampepfl/dotty}{https://\-github.com/\-lampepfl/\-dotty}},
     2784    howpublished= {\url{https://github.com/lampepfl/dotty}},
    27892785    note        = {Acessed: 2019-02-22}
    27902786}
     
    27972793    month       = nov,
    27982794    year        = 1983,
    2799     note        = {\href{http://www.lysator.liu.se/c/duffs-device.html}{http://\-www.lysator.liu.se/\-c/\-duffs-device.html}}
     2795    note        = {\url{http://www.lysator.liu.se/c/duffs-device.html}}
    28002796}
    28012797
     
    30333029    month       = aug,
    30343030    note        = {WikipediA},
    3035     howpublished= {\href{http://www.akkadia.org/drepper/tls.pdf}
    3036                   {http://\-www.akkadia.org/\-drepper/\-tls.pdf}},
     3031    howpublished= {\url{http://www.akkadia.org/drepper/tls.pdf}},
    30373032}
    30383033
     
    30453040    month       = may,
    30463041    note        = {Electronic Engineering Times},
    3047     howpublished= {\href{https://www.eetimes.com/author.asp?sectionid=36&doc_id=1287712}
    3048                   {https://\-www.eetimes.com/\-author.asp?sectionid=\-36&doc_id=1287712}},
     3042    howpublished= {\url{https://www.eetimes.com/author.asp?sectionid=36&doc_id=1287712}},
    30493043}
    30503044
     
    31593153    month       = sep,
    31603154    year        = 2016,
    3161     note        = {\href{http://erlang.org/doc/pdf/otp-system-documentation.pdf}{http://\-erlang.org/\-doc/\-pdf/\-otp-system-documentation.pdf}},
     3155    note        = {\url{http://erlang.org/doc/pdf/otp-system-documentation.pdf}},
    31623156}
    31633157
     
    34823476    title       = {Extensions to the {C} Language Family},
    34833477    year        = 2014,
    3484     howpublished= {\href{https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/C-Extensions.html}{https://\-gcc.gnu.org/\-onlinedocs/\-gcc-4.7.2/\-gcc/\-C\-Extensions.html}},
     3478    howpublished= {\url{https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/C-Extensions.html}},
    34853479}
    34863480
     
    35653559    month       = feb,
    35663560    publisher   = {John Wiley \& Sons},
    3567     note        = {\href{https://doi.org/10.1002/cpe.4183}{https://\-doi.org/\-10.1002/\-cpe.4183}}
     3561    note        = {\url{https://doi.org/10.1002/cpe.4183}}
    35683562}
    35693563
     
    35873581    title       = {Fibers},
    35883582    organization= {Microsoft, Windows Development Center},
    3589     address     = {\href{https://docs.microsoft.com/en-us/windows/desktop/ProcThread/fibers}{https://\-docs.microsoft.com/\-en-us/\-windows/\-desktop/\-ProcThread/\-fibers}},
     3583    address     = {\url{https://docs.microsoft.com/en-us/windows/desktop/ProcThread/fibers}},
    35903584    year        = 2018,
    35913585}
     
    36093603    month       = jan,
    36103604    address     = {Waterloo, Ontario, Canada, N2L 3G1},
    3611     note        = {\href{http://uwspace.uwaterloo.ca/bitstream/10012/3501/1/Thesis.pdf}{http://\-uwspace.uwaterloo.ca/\-bitstream/\-10012/\-3501/\-1/\-Thesis.pdf}},
     3605    note        = {\url{http://uwspace.uwaterloo.ca/bitstream/10012/3501/1/Thesis.pdf}},
    36123606}
    36133607
     
    36443638    title       = {Facebook Open-source Library},
    36453639    organization= {Facebook},
    3646     address     = {\href{https://github.com/facebook/folly}{https://\-github.com/\-facebook/\-folly}},
     3640    address     = {\url{https://github.com/facebook/folly}},
    36473641    year        = 2018,
    36483642}
     
    36853679    address     = {Geneva, Switzerland},
    36863680    year        = 2010,
    3687     note        = {\href{https://www.iso.org/standard/50459.html}{https://\-www.iso.org/\-standard/\-50459.html}},
     3681    note        = {\url{https://www.iso.org/standard/50459.html}},
    36883682}
    36893683
     
    36973691    address     = {Geneva, Switzerland},
    36983692    year        = 2018,
    3699     note        = {\href{https://www.iso.org/standard/72320.html}{https://\-www.iso.org/\-standard/\-72320.html}},
     3693    note        = {\url{https://www.iso.org/standard/72320.html}},
    37003694}
    37013695
     
    39283922    address     = {GNU},
    39293923    year        = 2016,
    3930     note        = {\href{https://gmplib.org}{https://\-gmplib.org}},
     3924    note        = {\url{https://gmplib.org}},
    39313925}
    39323926
     
    39393933    organization= {Google},
    39403934    year        = 2009,
    3941     note        = {\href{http://golang.org/ref/spec}{http://\-golang.org/\-ref/\-spec}},
     3935    note        = {\url{http://golang.org/ref/spec}},
    39423936}
    39433937
     
    40434037    edition     = {{S}imon {M}arlow},
    40444038    year        = 2010,
    4045     note        = {\href{https://haskell.org/definition/haskell2010.pdf}{https://\-haskell.org/\-definition/\-haskell2010.pdf}},
     4039    note        = {\url{https://haskell.org/definition/haskell2010.pdf}},
    40464040}
    40474041
     
    41184112    number      = 12,
    41194113    pages       = {2463-2500},
    4120     note        = {\url{https://onlinelibrary.wiley.com/doi/10.1002/spe.3262},
     4114    note        = {\url{https://onlinelibrary.wiley.com/doi/10.1002/spe.3262}},
    41214115}
    41224116
     
    41274121    year        = 2019,
    41284122    optaddress  = {Waterloo, Ontario, Canada, N2L 3G1},
    4129     note        = {\href{https://uwspace.uwaterloo.ca/handle/10012/14706}{https://\-uwspace.uwaterloo.ca/\-handle/\-10012/\-14706}},
     4123    note        = {\url{https://uwspace.uwaterloo.ca/handle/10012/14706}},
    41304124}
    41314125
     
    41864180    month       = sep,
    41874181    publisher   = {John Wiley \& Sons},
    4188     note        = {\href{https://doi.org/10.1002/cpe.4475}{https://\-doi.org/\-10.1002/\-cpe.4475}},
     4182    note        = {\url{https://doi.org/10.1002/cpe.4475}},
    41894183}
    41904184
     
    43204314    year        = 2003,
    43214315    optaddress  = {Waterloo, Ontario, Canada, N2L 3G1},
    4322     note        = {\href{http://plg.uwaterloo.ca/theses/BilsonThesis.pdf}{http://\-plg.uwaterloo.ca/\-theses/\-BilsonThesis.pdf}},
     4316    note        = {\url{http://plg.uwaterloo.ca/theses/BilsonThesis.pdf}},
    43234317}
    43244318
     
    47334727    title       = {JDK 1.1 for Solaris Developer's Guide},
    47344728    publisher   = {Oracle},
    4735     address     = {\href{https://docs.oracle.com/cd/E19455-01/806-3461/6jck06gqk/index.html#ch2mt-41}{https://\-docs.oracle.com/\-cd/\-E19455-01/\-806-3461/\-6jck06gqk/\-index.html\#ch2mt-41}},
     4729    address     = {\url{https://docs.oracle.com/cd/E19455-01/806-3461/6jck06gqk/index.html#ch2mt-41}},
    47364730    year        = 2010,
    47374731}
     
    47444738    organization= {Oracle},
    47454739    year        = 2014,
    4746     note        = {\href{http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html}{http://docs.oracle.com/\-javase/7/\-docs/\-api/\-java/\-util/\-concurrent/\-package-summary.html}},
     4740    note        = {\url{http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html}},
    47474741}
    47484742
     
    48734867    title       = {Labels as Values},
    48744868    year        = {since gcc-3},
    4875     howpublished= {\href{https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html}
    4876                   {https:\-//gcc.gnu.org/\-onlinedocs/\-gcc/\-Labels-as-Values.html}},
     4869    howpublished= {\url{https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html}},
    48774870}
    48784871
     
    49314924    title       = {libdill Thread Library},
    49324925    year        = 2019,
    4933     howpublished= {\href{http://libdill.org/libdill-2.14.tar.gz}
    4934                   {http://\-libdill.org/\-libdill-2.14.tar.gz}},
     4926    howpublished= {\url{http://libdill.org/libdill-2.14.tar.gz}},
    49354927}
    49364928
     
    49394931    author      = {Martin Karsten},
    49404932    title       = {{libfibre:~User-Level Threading Runtime}},
    4941     howpublished= {\href{https://git.uwaterloo.ca/mkarsten/libfibre}{https://\-git.uwaterloo.ca/\-mkarsten/\-libfibre}},
     4933    howpublished= {\url{https://git.uwaterloo.ca/mkarsten/libfibre}},
    49424934    note        = {[Online; accessed 2020-04-15]},
    49434935}
     
    49624954    title       = {{G}o-style concurrency in {C}, Version 1.18},
    49634955    organization= {libmill},
    4964     address     = {\href{http://libmill.org/documentation.html}{http://\-libmill.org/\-documentation.html}},
     4956    address     = {\url{http://libmill.org/documentation.html}},
    49654957    month       = jan,
    49664958    year        = 2017,
     
    50385030    month       = jan,
    50395031    year        = 2017,
    5040     howpublished= {\href{http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowering-rust-traits-to-logic/}
    5041                   {http://smallcultfollowing.com/\-babysteps/\-blog/\-2017/\-01/\-26/\-lowering-rust-traits-to-logic/}},
     5032    howpublished= {\url{http://smallcultfollowing.com/babysteps/blog/2017/01/26/lowering-rust-traits-to-logic/}},
    50425033    optnote     = {Accessed: 2019-01},
    50435034}
     
    50635054    title       = {Lua 5.4 Reference Manual},
    50645055    organization= {Pontifical Catholic University},
    5065     address     = {\href{https://www.lua.org/manual/5.4}{https://\-www.lua.org/\-manual/\-5.4}},
     5056    address     = {\url{https://www.lua.org/manual/5.4}},
    50665057    year        = 2020,
    50675058}
     
    50845075    title       = {Making arbitrarily-large binaries from fixed-size {C}{\kern-.1em\hbox{\large\texttt{+\kern-.25em+}}} code},
    50855076    year        = 2016,
    5086     howpublished= {\href{http://blog.reverberate.org/2016/01/making-arbitrarily-large-binaries-from.html}
    5087                   {http://blog.reverberate.org/\-2016/\-01/\-making-arbitrarily-large-binaries-from.html}},
     5077    howpublished= {\url{http://blog.reverberate.org/2016/01/making-arbitrarily-large-binaries-from.html}},
    50885078    optnote     = {Accessed: 2016-09},
    50895079}
     
    51185108    title       = {Marcel Thread Library},
    51195109    year        = 2011,
    5120     howpublished= {\href{https://gforge.inria.fr/frs/download.php/file/28643/marcel-2.99.3.tar.gz}
    5121                   {https://\-gforge.inria.fr/\-frs/\-download.php/\-file/\-28643/\-marcel-2.99.3.tar.gz}},
     5110    howpublished= {\url{https://gforge.inria.fr/frs/download.php/file/28643/marcel-2.99.3.tar.gz}},
    51225111}
    51235112
     
    52645253    month       = sep,
    52655254    year        = 1994,
    5266     note        = {\href{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uSystem.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-pub/\-uSystem/\-uSystem.pdf}},
     5255    note        = {\url{https://plg.uwaterloo.ca/~usystem/pub/uSystem/uSystem.pdf}},
    52675256}
    52685257
     
    54635452    month       = jun,
    54645453    year        = 2015,
    5465     note        = {\href{http://www.mpi-forum.org/docs/mpi-3.1/mpi31-report.pdf}{http://www.mpi-forum.org/\-docs/\-mpi-3.1/\-mpi31-report.pdf}},
     5454    note        = {\url{http://www.mpi-forum.org/docs/mpi-3.1/mpi31-report.pdf}},
    54665455}
    54675456
     
    56135602    year        = 1980,
    56145603    pages       = {833-842},
    5615     note        = {\href{http://groups.csail.mit.edu/tds/papers/Lynch/allertonconf.pdf}{http://\-groups.csail.mit.edu/\-tds/\-papers/\-Lynch/\-allertonconf.pdf} [Accessed on March 2014]},
     5604    note        = {\url{http://groups.csail.mit.edu/tds/papers/Lynch/allertonconf.pdf}},
    56165605    optnote     = {\textsf{http://\-groups.csail.mit.edu/\-tds/\-papers/\-Lynch/\-allertonconf.pdf}},
    56175606}
     
    56395628    institution = {Red Hat},
    56405629    year        = 2003,
    5641     note        = {\href{http://www.cs.utexas.edu/~witchel/372/lectures/POSIX_Linux_Threading.pdf}{http://www.cs.utexas.edu/\-$\sim$witchel/\-372/\-lectures/\-POSIX\_Linux\_Threading.pdf}},
     5630    note        = {\url{http://www.cs.utexas.edu/~witchel/372/lectures/POSIX_Linux_Threading.pdf}},
    56425631}
    56435632
     
    56495638    organization= {{gcc} 9.3 Manual},
    56505639    year        = 2019,
    5651     note        = {\href{https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Nested-Functions.html}{https://\-gcc.gnu.org/\-onlinedocs/\-gcc-9.3.0/\-gcc/\-Nested-Functions.html}},
     5640    note        = {\url{https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Nested-Functions.html}},
    56525641}
    56535642
     
    57185707    year        = 1990,
    57195708    pages       = {41-51},
    5720     note        = {\href{http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}{http://\-doc.cat-v.org/\-bell\_labs/\-new\_c\_compilers/\-new\_c\_compiler.pdf}},
     5709    note        = {\url{http://doc.cat-v.org/bell_labs/new_c_compilers/new_c_compiler.pdf}},
    57215710}
    57225711
     
    57815770    key         = {nginx},
    57825771    author      = {{NGINX}},
    5783     howpublished= {\href{https://www.nginx.com}{https://\-www.nginx.com}},
     5772    howpublished= {\url{https://www.nginx.com}},
    57845773}
    57855774
     
    59105899    publisher   = {Apple Inc.},
    59115900    year        = 2014,
    5912     howpublished= {\href{https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC}{https://\-developer.apple.com/\-library/archive/\-documentation/\-Cocoa/\-Conceptual/\-ProgrammingWithObjectiveC}},
     5901    howpublished= {\url{https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC}},
    59135902}
    59145903
     
    59195908    title       = {{X}code 7 Release Notes},
    59205909    year        = 2015,
    5921     howpublished= {\href{https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc7_release_notes.html}{https://\-developer.apple.com/\-library/\-content/\-documentation/\-Xcode/\-Conceptual/\-RN-Xcode-Archive/\-Chapters/\-xc7\_release\_notes.html}},
     5910    howpublished= {\url{https://developer.apple.com/library/content/documentation/Xcode/Conceptual/RN-Xcode-Archive/Chapters/xc7_release_notes.html}},
    59225911}
    59235912
     
    60526041    month       = nov,
    60536042    year        = 2015,
    6054     note        = {\href{https://www.openmp.org/wp-content/uploads/openmp-4.5.pdf}{https://\-www.openmp.org/\-wp-content/\-uploads/\-openmp-4.5.pdf}},
     6043    note        = {\url{https://www.openmp.org/wp-content/uploads/openmp-4.5.pdf}},
    60556044}
    60566045
     
    60606049    title       = {OpenTelemetry},
    60616050    author      = {{Asynkron AB}},
    6062     howpublished= {\href{https://proto.actor/docs/tracing}{https://\-proto.actor/\-docs/\-tracing}},
     6051    howpublished= {\url{https://proto.actor/docs/tracing}},
    60636052    year        = 2022,
    60646053}
     
    64616450    key         = {perf},
    64626451    author      = {perf},
    6463     howpublished= {\href{https://perf.wiki.kernel.org/index.php/Tutorial}{https://\-perf.wiki.kernel.org/\-index.php/\-Tutorial}},
     6452    howpublished= {\url{https://perf.wiki.kernel.org/index.php/Tutorial}},
    64646453}
    64656454
     
    64706459    month       = may,
    64716460    year        = 2012,
    6472     howpublished= {\href{http://cs.brown.edu/research/pubs/theses/masters/2012/verch.pdf}{http://cs.brown.edu/\-research/\-pubs/\-theses/\-masters/\-2012/\-verch.pdf}},
     6461    howpublished= {\url{http://cs.brown.edu/research/pubs/theses/masters/2012/verch.pdf}},
    64736462}
    64746463
     
    68696858    address     = {Geneva, Switzerland},
    68706859    year        = 1998,
    6871     note        = {\href{https://www.iso.org/standard/25845.html}{https://\-www.iso.org/\-standard/\-25845.html}},
     6860    note        = {\url{https://www.iso.org/standard/25845.html}},
    68726861}
    68736862
     
    68816870    address     = {Geneva, Switzerland},
    68826871    year        = 2014,
    6883     note        = {\href{https://www.iso.org/standard/64029.html}{https://\-www.iso.org/\-standard/\-64029.html}},
     6872    note        = {\url{https://www.iso.org/standard/64029.html}},
    68846873}
    68856874
     
    68936882    address     = {Geneva, Switzerland},
    68946883    year        = 2017,
    6895     note        = {\href{https://www.iso.org/standard/68564.html}{https://\-www.iso.org/\-standard/\-68564.html}},
     6884    note        = {\url{https://www.iso.org/standard/68564.html}},
    68966885}
    68976886
     
    71737162    author      = {IEEE and {The Open Group}},
    71747163    year        = 2018,
    7175     howpublished= {\href{http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html}
    7176                   {http://\-pubs.opengroup.org/\-onlinepubs/\-9699919799/\-basedefs/\-pthread.h.html}},
     7164    howpublished= {\url{http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html}},
    71777165}
    71787166
     
    71837171    title       = {Python Language Reference, Release 3.7.2},
    71847172    organization= {Python Software Foundation},
    7185     address     = {\href{https://docs.python.org/3/reference/index.html}{https://\-docs.python.org/\-3/\-reference/\-index.html}},
     7173    address     = {\url{https://docs.python.org/3/reference/index.html}},
    71867174    year        = 2018,
    71877175}
     
    72387226    title       = {Quasar Documentation, Release 0.8.0},
    72397227    organization= {Parallel Universe},
    7240     address     = {\href{http://docs.paralleluniverse.co/quasar}{http://\-docs.paralleluniverse.co/\-quasar}},
     7228    address     = {\url{http://docs.paralleluniverse.co/quasar}},
    72417229    year        = 2018,
    72427230}
     
    73787366    month       = apr,
    73797367    type        = {Diplomarbeit},
    7380     note        = {\href{https://plg.uwaterloo.ca/~usystem/theses/SchusterThesis.pdf}{https://\-plg.uwaterloo.ca/\-$\sim$usystem/\-theses/\-SchusterThesis.pdf}},
     7368    note        = {\url{https://plg.uwaterloo.ca/~usystem/theses/SchusterThesis.pdf}},
    73817369}
    73827370
     
    74137401    year        = 2017,
    74147402    optaddress  = {Waterloo, Ontario, Canada, N2L 3G1},
    7415     note        = {\href{https://uwspace.uwaterloo.ca/handle/10012/11830}{https://\-uwspace.uwaterloo.ca/\-handle/\-10012/\-11830}},
     7403    note        = {\url{https://uwspace.uwaterloo.ca/handle/10012/11830}},
    74167404}
    74177405
     
    74917479    month       = apr,
    74927480    year        = 2022,
    7493     howpublished= {\href{https://github.com/mjansson/rpmalloc}{https://\-github.com/\-mjansson/\-rpmalloc}},
     7481    howpublished= {\url{https://github.com/mjansson/rpmalloc}},
    74947482}
    74957483
     
    75017489    optaddress  = {Rust Project Developers},
    75027490    year        = 2015,
    7503     note        = {\href{https://doc.rust-lang.org/reference.html}{https://\-doc.rust-lang\-.org/\-reference.html}},
     7491    note        = {\url{https://doc.rust-lang.org/reference.html}},
    75047492}
    75057493
     
    75107498    title       = {Ruby Documentation, Release 2.6.0},
    75117499    organization= {Python Software Foundation},
    7512     address     = {\href{https://www.ruby-lang.org/en/documentation}{https://\-www.ruby-lang.org/\-en/\-documentation}},
     7500    address     = {\url{https://www.ruby-lang.org/en/documentation}},
    75137501    year        = 2018,
    75147502}
     
    75387526    address     = {\'{E}cole Polytechnique F\'{e}d\'{e}rale de Lausanne},
    75397527    year        = 2016,
    7540     note        = {\href{http://www.scala-lang.org/files/archive/spec/2.11}{http://\-www.scala-lang.org/\-files/\-archive/\-spec/\-2.11}},
     7528    note        = {\url{http://www.scala-lang.org/files/archive/spec/2.11}},
    75417529}
    75427530
     
    76997687    month       = sep,
    77007688    year        = 1995,
    7701     note        = {\href{http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-95-7.pdf}{http://www.hpl.hp.com/\-techreports/\-Compaq-DEC/\-WRL-95-7.pdf}, Reprinted in \cite{Adve95reprint}.},
     7689    note        = {\url{http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-95-7.pdf}},
    77027690}
    77037691
     
    77737761    month       = may,
    77747762    year        = 2001,
    7775     note        = {\href{http://www.python.org/peps/pep-0255.html}{http://\-www.python.org/\-peps/\-pep-0255.html}},
     7763    note        = {\url{http://www.python.org/peps/pep-0255.html}},
    77767764}
    77777765
     
    80768064    organization= {IEEE and The Open Group},
    80778065    year        = 2017,
    8078     note        = {\href{https://pubs.opengroup.org/onlinepubs/9699919799}{https://\-pubs.opengroup.org/\-onlinepubs/\-9699919799}},
     8066    note        = {\url{https://pubs.opengroup.org/onlinepubs/9699919799}},
    80798067}
    80808068
     
    81438131    pages       = {1-6},
    81448132    numpages    = {6},
    8145     howpublished= {\href{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf}{http://\-www.open-std.org/\-jtc1/\-sc22/\-wg21/\-docs/\-papers/\-2015/\-p0144r0.pdf}},
     8133    howpublished= {\url{http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf}},
    81468134}
    81478135
     
    84538441    key         = {TIOBE Index},
    84548442    author      = {{TIOBE Index}},
    8455     howpublished= {\href{http://www.tiobe.com/tiobe_index}{http://\-www.tiobe.com/\-tiobe\_index}},
     8443    howpublished= {\url{http://www.tiobe.com/tiobe_index}},
    84568444}
    84578445
     
    84618449    title       = {Thread (computing)},
    84628450    author      = {{Threading Model}},
    8463     howpublished= {\href{https://en.wikipedia.org/wiki/Thread_(computing)}{https://\-en.wikipedia.org/\-wiki/\-Thread\_\-(computing)}},
     8451    howpublished= {\url{https://en.wikipedia.org/wiki/Thread_(computing)}},
    84648452}
    84658453
     
    84698457    title       = {{T}okio Asynchronous Runtime for {R}ust},
    84708458    author      = {Tokio},
    8471     howpublished= {\href{https://tokio.rs}{https://\-tokio.rs}},
     8459    howpublished= {\url{https://tokio.rs}},
    84728460}
    84738461
     
    86098597    key         = {Trace Compass},
    86108598    author      = {{T}race {C}ompass},
    8611     howpublished= {\href{https://projects.eclipse.org/proposals/trace-compass}{https://\-projects.eclipse.org/\-proposals/\-trace-compass}},
     8599    howpublished= {\url{https://projects.eclipse.org/proposals/trace-compass}},
    86128600}
    86138601
     
    86688656    title       = {Typed Actors},
    86698657    author      = {{Lightbend}},
    8670     howpublished= {\href{https://doc.akka.io/docs/akka/2.5/typed-actors.html}{https://\-doc.akka.io/\-docs/\-akka/\-2.5/\-typed-actors.html}},
     8658    howpublished= {\url{https://doc.akka.io/docs/akka/2.5/typed-actors.html}},
    86718659    year        = 2022,
    86728660}
     
    89388926    year        = 2020,
    89398927    note        = {WikipediA},
    8940     howpublished= {\href{https://en.wikipedia.org/wiki/Visitor\_pattern}
    8941                   {https://\-en.wikipedia.org/\-wiki/\-Visitor\_pattern}},
     8928    howpublished= {\url{https://en.wikipedia.org/wiki/Visitor\_pattern}},
    89428929}
    89438930
     
    90419028    month       = jun,
    90429029    year        = 1985,
    9043     note        = {\href{http://www.hpl.hp.com/techreports/tandem/TR-85.7.pdf}{http://www.hpl.hp.com/\-techreports/\-tandem/\-TR-85.7.pdf}},
     9030    note        = {\url{http://www.hpl.hp.com/techreports/tandem/TR-85.7.pdf}},
    90449031}
    90459032
  • doc/papers/llheap/Paper.tex

    rc75b30a r32490deb  
    7777\lstset{
    7878columns=fullflexible,
    79 basicstyle=\linespread{0.9}\sf,                                                 % reduce line spacing and use sanserif font
    80 stringstyle=\tt,                                                                                % use typewriter font
    81 tabsize=5,                                                                                              % N space tabbing
    82 xleftmargin=\parindentlnth,                                                             % indent code to paragraph indentation
    83 %mathescape=true,                                                                               % LaTeX math escape in CFA code $...$
    84 escapechar=\$,                                                                                  % LaTeX escape in CFA code
    85 keepspaces=true,                                                                                %
    86 showstringspaces=false,                                                                 % do not show spaces with cup
    87 showlines=true,                                                                                 % show blank lines at end of code
    88 aboveskip=4pt,                                                                                  % spacing above/below code block
    89 belowskip=3pt,
    90 moredelim=**[is][\color{red}]{`}{`},
     79basicstyle=\linespread{0.9}\sf,                 % reduce line spacing and use sanserif font
     80stringstyle=\small\tt,                                  % use typewriter font
     81tabsize=5,                                                              % N space tabbing
     82xleftmargin=\parindentlnth,                             % indent code to paragraph indentation
     83escapechar=\$,                                                  % LaTeX escape in CFA code
     84%mathescape=true,                                               % LaTeX math escape in CFA code $...$
     85keepspaces=true,                                                %
     86showstringspaces=false,                                 % do not show spaces with cup
     87showlines=true,                                                 % show blank lines at end of code
     88aboveskip=4pt,                                                  % spacing above/below code block
     89belowskip=2pt,
     90numberstyle=\footnotesize\sf,                   % numbering style
     91moredelim=**[is][\color{red}]{@}{@},
    9192}% lstset
    9293
     
    10821083
    10831084The primary design objective for llheap is low-latency across all allocator calls independent of application access-patterns and/or number of threads, \ie very seldom does the allocator have a delay during an allocator call.
    1084 (Large allocations requiring initialization, \eg zero fill, and/or copying are not covered by the low-latency objective.)
     1085Excluded from the low-latency objective are (large) allocations requiring initialization, \eg zero fill, and/or data copying, which are outside the allocator's purview.
    10851086A direct consequence of this objective is very simple or no storage coalescing;
    10861087hence, llheap's design is willing to use more storage to lower latency.
    10871088This objective is apropos because systems research and industrial applications are striving for low latency and computers have huge amounts of RAM memory.
    1088 Finally, llheap's performance should be comparable with the current best allocators (see performance comparison in Section~\ref{c:Performance}).
     1089Finally, llheap's performance should be comparable with the current best allocators, both in space and time (see performance comparison in Section~\ref{c:Performance}).
    10891090
    10901091% The objective of llheap's new design was to fulfill following requirements:
     
    12051206% \label{s:AllocationFastpath}
    12061207
    1207 llheap's design was reviewed and changed multiple times during its development.  Only the final design choices are
    1208 discussed in this paper.
     1208llheap's design was reviewed and changed multiple times during its development, with the final choices are discussed here.
    12091209(See~\cite{Zulfiqar22} for a discussion of alternate choices and reasons for rejecting them.)
    12101210All designs were analyzed for the allocation/free \newterm{fastpath}, \ie when an allocation can immediately return free storage or returned storage is not coalesced.
    1211 The heap model choosen is 1:1, which is the T:H model with T = H, where there is one thread-local heap for each KT.
     1211The heap model chosen is 1:1, which is the T:H model with T = H, where there is one thread-local heap for each KT.
    12121212(See Figure~\ref{f:THSharedHeaps} but with a heap bucket per KT and no bucket or local-pool lock.)
    12131213Hence, immediately after a KT starts, its heap is created and just before a KT terminates, its heap is (logically) deleted.
     
    14261426
    14271427
    1428 Algorithm~\ref{alg:heapObjectFreeOwn} shows the de-allocation (free) outline for an object at address $A$ with ownership.
     1428Algorithm~\ref{alg:heapObjectFreeOwn} shows the deallocation (free) outline for an object at address $A$ with ownership.
    14291429First, the address is divided into small (@sbrk@) or large (@mmap@).
    14301430For large allocations, the storage is unmapped back to the OS.
     
    14331433If the bucket is not local to the thread, the allocation is pushed onto the owning thread's associated away stack.
    14341434
    1435 Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the de-allocation (free) outline for an object at address $A$ without ownership.
     1435Algorithm~\ref{alg:heapObjectFreeNoOwn} shows the deallocation (free) outline for an object at address $A$ without ownership.
    14361436The algorithm is the same as for ownership except if the bucket is not local to the thread.
    14371437Then the corresponding bucket of the owner thread is computed for the deallocating thread, and the allocation is pushed onto the deallocating thread's bucket.
     
    17921792The C dynamic-memory API is extended with the following routines:
    17931793
    1794 \paragraph{\lstinline{void * aalloc( size_t dim, size_t elemSize )}}
    1795 extends @calloc@ for allocating a dynamic array of objects without calculating the total size of array explicitly but \emph{without} zero-filling the memory.
    1796 @aalloc@ is significantly faster than @calloc@, which is the only alternative given by the standard memory-allocation routines.
    1797 
    1798 \noindent\textbf{Usage}
    1799 @aalloc@ takes two parameters.
    1800 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1801 \item
    1802 @dim@: number of array objects
    1803 \item
    1804 @elemSize@: size of array object
    1805 \end{itemize}
     1794\medskip\noindent
     1795\lstinline{void * aalloc( size_t dim, size_t elemSize )}
     1796extends @calloc@ for allocating a dynamic array of objects with total size @dim@ $\times$ @elemSize@ but \emph{without} zero-filling the memory.
     1797@aalloc@ is significantly faster than @calloc@, which is the only alternative given by the standard memory-allocation routines for array allocation.
    18061798It returns the address of the dynamic array or @NULL@ if either @dim@ or @elemSize@ are zero.
    18071799
    1808 \paragraph{\lstinline{void * resize( void * oaddr, size_t size )}}
    1809 extends @realloc@ for resizing an existing allocation \emph{without} copying previous data into the new allocation or preserving sticky properties.
     1800\medskip\noindent
     1801\lstinline{void * resize( void * oaddr, size_t size )}
     1802extends @realloc@ for resizing an existing allocation, @oaddr@, to the new @size@ (smaller or larger than previous) \emph{without} copying previous data into the new allocation or preserving sticky properties.
    18101803@resize@ is significantly faster than @realloc@, which is the only alternative.
    1811 
    1812 \noindent\textbf{Usage}
    1813 @resize@ takes two parameters.
    1814 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1815 \item
    1816 @oaddr@: address to be resized
    1817 \item
    1818 @size@: new allocation size (smaller or larger than previous)
    1819 \end{itemize}
    18201804It returns the address of the old or new storage with the specified new size or @NULL@ if @size@ is zero.
    18211805
    1822 \paragraph{\lstinline{void * amemalign( size_t alignment, size_t dim, size_t elemSize )}}
    1823 extends @aalloc@ and @memalign@ for allocating an aligned dynamic array of objects.
     1806\medskip\noindent
     1807\lstinline{void * amemalign( size_t alignment, size_t dim, size_t elemSize )}
     1808extends @aalloc@ and @memalign@ for allocating a dynamic array of objects with the starting address on the @alignment@ boundary.
    18241809Sets sticky alignment property.
    1825 
    1826 \noindent\textbf{Usage}
    1827 @amemalign@ takes three parameters.
    1828 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1829 \item
    1830 @alignment@: alignment requirement
    1831 \item
    1832 @dim@: number of array objects
    1833 \item
    1834 @elemSize@: size of array object
    1835 \end{itemize}
    18361810It returns the address of the aligned dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero.
    18371811
    1838 \paragraph{\lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )}}
     1812\medskip\noindent
     1813\lstinline{void * cmemalign( size_t alignment, size_t dim, size_t elemSize )}
    18391814extends @amemalign@ with zero fill and has the same usage as @amemalign@.
    18401815Sets sticky zero-fill and alignment property.
    18411816It returns the address of the aligned, zero-filled dynamic-array or @NULL@ if either @dim@ or @elemSize@ are zero.
    18421817
    1843 \paragraph{\lstinline{size_t malloc_alignment( void * addr )}}
    1844 returns the alignment of the dynamic object for use in aligning similar allocations.
    1845 
    1846 \noindent\textbf{Usage}
    1847 @malloc_alignment@ takes one parameter.
    1848 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1849 \item
    1850 @addr@: address of an allocated object.
    1851 \end{itemize}
    1852 It returns the alignment of the given object, where objects not allocated with alignment return the minimal allocation alignment.
    1853 
    1854 \paragraph{\lstinline{bool malloc_zero_fill( void * addr )}}
    1855 returns true if the object has the zero-fill sticky property for use in zero filling similar allocations.
    1856 
    1857 \noindent\textbf{Usage}
    1858 @malloc_zero_fill@ takes one parameters.
    1859 
    1860 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1861 \item
    1862 @addr@: address of an allocated object.
    1863 \end{itemize}
    1864 It returns true if the zero-fill sticky property is set and false otherwise.
    1865 
    1866 \paragraph{\lstinline{size_t malloc_size( void * addr )}}
    1867 returns the request size of the dynamic object (updated when an object is resized) for use in similar allocations.
    1868 See also @malloc_usable_size@.
    1869 
    1870 \noindent\textbf{Usage}
    1871 @malloc_size@ takes one parameters.
    1872 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1873 \item
    1874 @addr@: address of an allocated object.
    1875 \end{itemize}
    1876 It returns the request size or zero if @addr@ is @NULL@.
    1877 
    1878 \paragraph{\lstinline{int malloc_stats_fd( int fd )}}
    1879 changes the file descriptor where @malloc_stats@ writes statistics (default @stdout@).
    1880 
    1881 \noindent\textbf{Usage}
    1882 @malloc_stats_fd@ takes one parameters.
    1883 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1884 \item
    1885 @fd@: file descriptor.
    1886 \end{itemize}
    1887 It returns the previous file descriptor.
    1888 
    1889 \paragraph{\lstinline{size_t malloc_expansion()}}
     1818\medskip\noindent
     1819\lstinline{size_t malloc_alignment( void * addr )}
     1820returns the object alignment, where objects not allocated with alignment return the minimal allocation alignment.
     1821For use in aligning similar allocations.
     1822
     1823\medskip\noindent
     1824\lstinline{bool malloc_zero_fill( void * addr )}
     1825returns true if the objects zero-fill sticky property is set and false otherwise.
     1826For use in zero filling similar allocations.
     1827
     1828\medskip\noindent
     1829\lstinline{size_t malloc_size( void * addr )}
     1830returns the object's request size, which is updated when an object is resized or zero if @addr@ is @NULL@ (see also @malloc_usable_size@).
     1831For use in similar allocations.
     1832
     1833\medskip\noindent
     1834\lstinline{int malloc_stats_fd( int fd )}
     1835changes the file descriptor where @malloc_stats@ writes statistics (default @stdout@) and returns the previous file descriptor.
     1836
     1837\medskip\noindent
     1838\lstinline{size_t malloc_expansion()}
    18901839\label{p:malloc_expansion}
    18911840set the amount (bytes) to extend the heap when there is insufficient free storage to service an allocation request.
    18921841It returns the heap extension size used throughout a program when requesting more memory from the system using @sbrk@ system-call, \ie called once at heap initialization.
    18931842
    1894 \paragraph{\lstinline{size_t malloc_mmap_start()}}
     1843\medskip\noindent
     1844\lstinline{size_t malloc_mmap_start()}
    18951845set the crossover between allocations occurring in the @sbrk@ area or separately mapped.
    18961846It returns the crossover point used throughout a program, \ie called once at heap initialization.
    18971847
    1898 \paragraph{\lstinline{size_t malloc_unfreed()}}
     1848\medskip\noindent
     1849\lstinline{size_t malloc_unfreed()}
    18991850\label{p:malloc_unfreed}
    19001851amount subtracted to adjust for unfreed program storage (debug only).
    1901 It returns the new subtraction amount and called by @malloc_stats@.
     1852It returns the new subtraction amount and called by @malloc_stats@ (discussed in Section~\ref{}).
    19021853
    19031854
     
    19061857The following extensions take advantage of overload polymorphism in the \CC type-system.
    19071858
    1908 \paragraph{\lstinline{void * resize( void * oaddr, size_t nalign, size_t size )}}
    1909 extends @resize@ with an alignment re\-quirement.
    1910 
    1911 \noindent\textbf{Usage}
    1912 takes three parameters.
    1913 \begin{itemize}[topsep=3pt,itemsep=2pt,parsep=0pt]
    1914 \item
    1915 @oaddr@: address to be resized
    1916 \item
    1917 @nalign@: alignment requirement
    1918 \item
    1919 @size@: new allocation size (smaller or larger than previous)
    1920 \end{itemize}
     1859\medskip\noindent
     1860\lstinline{void * resize( void * oaddr, size_t nalign, size_t size )}
     1861extends @resize@ with an alignment requirement, @nalign@.
    19211862It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero.
    19221863
    1923 \paragraph{\lstinline{void * realloc( void * oaddr, size_t nalign, size_t size )}}
    1924 extends @realloc@ with an alignment re\-quirement and has the same usage as aligned @resize@.
     1864\medskip\noindent
     1865\lstinline{void * realloc( void * oaddr, size_t nalign, size_t size )}
     1866extends @realloc@ with an alignment requirement, @nalign@.
     1867It returns the address of the old or new storage with the specified new size and alignment, or @NULL@ if @size@ is zero.
    19251868
    19261869
     
    19791922object size: like the \CFA's C-interface, programmers do not have to specify object size or cast allocation results.
    19801923\end{itemize}
    1981 Note, postfix function call is an alternative call syntax, using backtick @`@, where the argument appears before the function name, \eg
     1924Note, postfix function call is an alternative call syntax, using backtick @`@, so the argument appears before the function name, \eg
    19821925\begin{cfa}
    19831926duration ?@`@h( int h );                // ? denote the position of the function operand
     
    19871930\end{cfa}
    19881931
    1989 \paragraph{\lstinline{T * alloc( ... )} or \lstinline{T * alloc( size_t dim, ... )}}
     1932The following extensions take advantage of overload polymorphism in the \CC type-system.
     1933
     1934\medskip\noindent
     1935\lstinline{T * alloc( ... )} or \lstinline{T * alloc( size_t dim, ... )}
    19901936is overloaded with a variable number of specific allocation operations, or an integer dimension parameter followed by a variable number of specific allocation operations.
    19911937These allocation operations can be passed as named arguments when calling the \lstinline{alloc} routine.
     
    19961942
    19971943The allocation property functions are:
    1998 \subparagraph{\lstinline{T_align ?`align( size_t alignment )}}
     1944
     1945\medskip\noindent
     1946\lstinline{T_align ?`align( size_t alignment )}
    19991947to align the allocation.
    2000 The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two, \eg:
     1948The alignment parameter must be $\ge$ the default alignment (@libAlign()@ in \CFA) and a power of two.
     1949The following example returns a dynamic object and object array aligned on a 4096-byte boundary.
    20011950\begin{cfa}
    20021951int * i0 = alloc( @4096`align@ );  sout | i0 | nl;
     
    200619550x555555574000 0x555555574000 0x555555574004 0x555555574008
    20071956\end{cfa}
    2008 returns a dynamic object and object array aligned on a 4096-byte boundary.
    2009 
    2010 \subparagraph{\lstinline{S_fill(T) ?`fill ( /* various types */ )}}
     1957
     1958\medskip\noindent
     1959\lstinline{S_fill(T) ?`fill ( /* various types */ )}
    20111960to initialize storage.
    20121961There are three ways to fill storage:
    2013 \begin{enumerate}
     1962\begin{enumerate}[itemsep=0pt,parsep=0pt]
    20141963\item
    20151964A char fills each byte of each object.
     
    20201969\end{enumerate}
    20211970For example:
    2022 \begin{cfa}[numbers=left]
     1971\begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
    20231972int * i0 = alloc( @0n`fill@ );  sout | *i0 | nl;  // disambiguate 0
    20241973int * i1 = alloc( @5`fill@ );  sout | *i1 | nl;
     
    20291978int * i6 = alloc( 5, @[i3, 3]`fill@ );  for ( i; 5 ) sout | i6[i]; sout | nl;
    20301979\end{cfa}
    2031 \begin{lstlisting}[numbers=left]
     1980\begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
    203219810
    203319825
     
    20411990Examples 4 to 7 fill an array of objects with values, another array, or part of an array.
    20421991
    2043 \subparagraph{\lstinline{S_resize(T) ?`resize( void * oaddr )}}
     1992\medskip\noindent
     1993\lstinline{S_resize(T) ?`resize( void * oaddr )}
    20441994used to resize, realign, and fill, where the old object data is not copied to the new object.
    20451995The old object type may be different from the new object type, since the values are not used.
    20461996For example:
    2047 \begin{cfa}[numbers=left]
     1997\begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
    20481998int * i = alloc( @5`fill@ );  sout | i | *i;
    20491999i = alloc( @i`resize@, @256`align@, @7`fill@ );  sout | i | *i;
    20502000double * d = alloc( @i`resize@, @4096`align@, @13.5`fill@ );  sout | d | *d;
    20512001\end{cfa}
    2052 \begin{lstlisting}[numbers=left]
     2002\begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
    205320030x55555556d5c0 5
    205420040x555555570000 7
     
    20572007Examples 2 to 3 change the alignment, fill, and size for the initial storage of @i@.
    20582008
    2059 \begin{cfa}[numbers=left]
     2009\begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
    20602010int * ia = alloc( 5, @5`fill@ );  for ( i; 5 ) sout | ia[i]; sout | nl;
    20612011ia = alloc( 10, @ia`resize@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl;
     
    20632013ia = alloc( 3, @ia`resize@, @4096`align@, @2`fill@ );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl;
    20642014\end{cfa}
    2065 \begin{lstlisting}[numbers=left]
     2015\begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
    206620165 5 5 5 5
    206720177 7 7 7 7 7 7 7 7 7
     
    20712021Examples 2 to 4 change the array size, alignment and fill for the initial storage of @ia@.
    20722022
    2073 \subparagraph{\lstinline{S_realloc(T) ?`realloc( T * a ))}}
     2023\medskip\noindent
     2024\lstinline{S_realloc(T) ?`realloc( T * a ))}
    20742025used to resize, realign, and fill, where the old object data is copied to the new object.
    20752026The old object type must be the same as the new object type, since the value is used.
    20762027Note, for @fill@, only the extra space after copying the data from the old object is filled with the given parameter.
    20772028For example:
    2078 \begin{cfa}[numbers=left]
     2029\begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
    20792030int * i = alloc( @5`fill@ );  sout | i | *i;
    20802031i = alloc( @i`realloc@, @256`align@ );  sout | i | *i;
    20812032i = alloc( @i`realloc@, @4096`align@, @13`fill@ );  sout | i | *i;
    20822033\end{cfa}
    2083 \begin{lstlisting}[numbers=left]
     2034\begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
    208420350x55555556d5c0 5
    208520360x555555570000 5
     
    20892040The @13`fill@ in example 3 does nothing because no extra space is added.
    20902041
    2091 \begin{cfa}[numbers=left]
     2042\begin{cfa}[numbers=left,xleftmargin=2.5\parindentlnth]
    20922043int * ia = alloc( 5, @5`fill@ );  for ( i; 5 ) sout | ia[i]; sout | nl;
    20932044ia = alloc( 10, @ia`realloc@, @7`fill@ ); for ( i; 10 ) sout | ia[i]; sout | nl;
     
    20952046ia = alloc( 3, @ia`realloc@, @4096`align@, @2`fill@ );  sout | ia; for ( i; 3 ) sout | &ia[i] | ia[i]; sout | nl;
    20962047\end{cfa}
    2097 \begin{lstlisting}[numbers=left]
     2048\begin{lstlisting}[numbers=left,xleftmargin=2.5\parindentlnth]
    209820495 5 5 5 5
    209920505 5 5 5 5 7 7 7 7 7
  • doc/proposals/enum.tex

    rc75b30a r32490deb  
    77\usepackage{graphics}
    88\usepackage{xspace}
     9\usepackage{relsize}                                                                    % must be after change to small or selects old size
     10\usepackage{calc}                                                                               % latex arithmetic
    911
    1012\makeatletter
     
    2224\newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
    2325\newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
     26
     27\newcommand{\LstBasicStyle}[1]{{\lst@basicstyle{#1}}}
     28\newcommand{\LstKeywordStyle}[1]{{\lst@basicstyle{\lst@keywordstyle{#1}}}}
     29\newcommand{\LstCommentStyle}[1]{{\lst@basicstyle{\lst@commentstyle{#1}}}}
     30\newcommand{\LstStringStyle}[1]{{\lst@basicstyle{\lst@stringstyle{#1}}}}
     31\newcommand{\LstNumberStyle}[1]{{\lst@basicstyle{\lst@numberstyle{#1}}}}
     32
     33\newlength{\gcolumnposn}                                % temporary hack because lstlisting does not handle tabs correctly
     34\newlength{\columnposn}
     35\setlength{\gcolumnposn}{3in}
     36\setlength{\columnposn}{\gcolumnposn}
     37\newcommand{\setgcolumn}[1]{\global\gcolumnposn=#1\global\columnposn=\gcolumnposn}
     38\newcommand{\C}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstCommentStyle{#2}}}
     39\newcommand{\CD}[2][\@empty]{\ifx#1\@empty\else\global\setlength{\columnposn}{#1}\global\columnposn=\columnposn\fi\hfill\makebox[\textwidth-\columnposn][l]{\LstBasicStyle{#2}}}
     40\newcommand{\CRT}{\global\columnposn=\gcolumnposn}
    2441\makeatother
    2542
     
    4865\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    4966\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     67\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    5068\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    5169
     
    5674
    5775\lstdefinestyle{CStyle}{
    58 %    backgroundcolor=\color{backgroundColour},   
     76%    backgroundcolor=\color{backgroundColour},
    5977%    commentstyle=\color{mGreen},
    6078%    keywordstyle=\color{magenta},
     
    6482    basicstyle=\small\linespread{0.9}\sf,       % reduce line spacing and use sanserif font
    6583%   basicstyle=\footnotesize,
    66     breakatwhitespace=false,         
    67 %    breaklines=true,                 
    68     captionpos=b,                   
    69     keepspaces=true,                 
     84    breakatwhitespace=false,
     85%    breaklines=true,
     86    captionpos=b,
     87    keepspaces=true,
    7088        escapechar=\$,                                                  % LaTeX escape in CFA code
    71 %    numbers=left,                   
    72 %    numbersep=5pt,                 
     89%    numbers=left,
     90%    numbersep=5pt,
    7391%    numberstyle=\tiny\color{mGray},
    74 %    showspaces=false,               
     92%    showspaces=false,
    7593    showstringspaces=false,
    76 %    showtabs=false,                 
     94%    showtabs=false,
    7795        showlines=true,                                                 % show blank lines at end of code
    7896    tabsize=5,
     
    93111
    94112\begin{abstract}
    95 An enumeration is a type that defines a list of named constant values in C (and other languages).
    96 C and \CC use an integral type as the underlying representation of an enumeration.
    97 \CFA extends C enumerations to allow all basic and custom types for the inner representation.
     113An enumeration is a type defining an ordered set of named constant values, where a name abstracts a value, e.g., @PI@ versus @3.145159@.
     114C restrict an enumeration type to the integral type @signed int@, which \CC support , meaning enumeration names bind to integer constants.
     115\CFA extends C enumerations to allow all basic and custom types for the enumeration type, like other modern programming languages.
     116Furthermore, \CFA adds other useful features for enumerations to support better software-engineering practices and simplify program development.
    98117\end{abstract}
    99118
     119\section{Background}
     120
     121Naming values is a common practice in mathematics and engineering, e.g., $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MHz (1E6), etc.
     122Naming is also commonly used to represent many other numerical phenomenon, such as days of the week, months of a year, floors of a building (basement), time (noon, New Years).
     123Many programming languages capture this important capability through a mechanism called an \newterm{enumeration}.
     124An enumeration is similar to other programming-language types by providing a set of constrained values, but adds the ability to name \emph{all} the values in its set.
     125Note, all enumeration names must be unique but different names can represent the same value (eight note, quaver), which are synonyms.
     126
     127Specifically, an enumerated type is a type whose values are restricted to a fixed set of named constants.
     128Fundamentally, all types are restricted to a fixed set of values because of the underlying von Neumann architecture, and hence, to a corresponding set of constants, e.g., @3@, @3.5@, @3.5+2.1i@, @'c'@, @"abc"@, etc.
     129However, the values for basic types are not named, other than the programming-language supplied constants.
     130
     131
    100132\section{C-Style Enum}
    101133
    102 \CFA supports the C-Style enumeration using the same syntax and semantics.
     134The C-Style enumeration has the following syntax and semantics.
    103135\begin{lstlisting}[label=lst:weekday]
    104 enum Weekday { Monday, Tuesday, Wednesday, Thursday=10, Friday, Saturday, Sunday };
    105                 $\(\uparrow\)$                                                                      $\(\uparrow\)$
    106     ${\rm \newterm{enumeration name}}$                                        ${\rm \newterm{enumerator names}}
    107 \end{lstlisting}
    108 The example defines an enumeration type @Weekday@ with ordered enumerators @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     136enum Weekday { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday };
     137                $\(\uparrow\)$                                                                        $\(\uparrow\)$
     138    ${\rm \newterm{enumeration name}}$                                          ${\rm \newterm{enumerator names}}
     139\end{lstlisting}
     140Here, the enumeration type @Weekday@ defines the ordered \newterm{enumerator}s @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
    109141The successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@.
    110 A C enumeration is an integral type, with consecutive enumerator values assigned by the compiler starting at zero or the next explicitly initialized value by the programmer.
    111 For example, @Monday@ to @Wednesday@ have values 0--2 implicitly set by the compiler, @Thursday@ is explicitly set to @10@ by the programmer, and @Friday@ to @Sunday@ have values 11--13 implicitly set by the compiler.
     142A C enumeration is implemented by an integral type, with consecutive enumerator values assigned by the compiler starting at zero or the next explicitly initialized value.
     143For example, @Monday@ to @Wednesday@ have values 0--2 implicitly set by the compiler, @Thursday@ is explicitly set to @10@, and @Friday@ to @Sunday@ have values 11--13 implicitly set by the compiler.
    112144
    113145There are 3 attributes for an enumeration: \newterm{position}, \newterm{label}, and \newterm{value}:
     
    118150\it position            & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
    119151\it label                       & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
    120 \it value                       & 0                     & 1                     & 2                             & 10                    & 11            & 12            & 13
     152\it value                       & 0                     & 1                     & 2                             & {\color{red}10}& 11           & 12            & 13
    121153\end{tabular}
    122154\end{cquote}
    123155
    124156The enumerators of an enumeration are unscoped, i.e., enumerators declared inside of an @enum@ are visible in the enclosing scope of the @enum@ type.
     157Furthermore, there is an implicit bidirectional conversion between an enumeration and integral types.
    125158\begin{lstlisting}[label=lst:enum_scope]
    126159{
    127         enum Weekday { ... };   // enumerators implicitly projected into local scope
     160        enum Weekday { ... };                           $\C{// enumerators implicitly projected into local scope}$
    128161        Weekday weekday = Monday;
    129         weekday = Friday;
    130         int i = Sunday  // i == 13
     162        weekday = Friday;                                       $\C{// weekday == 11}$
     163        int i = Sunday                                          $\C{// i == 13}$
     164        weekday = 10000;                                        $\C{// undefined behaviour}$
    131165}
    132 int j = Wednesday; // ERROR! Wednesday is not declared in this scope
     166int j = Wednesday;                                              $\C{// ERROR! Wednesday is not declared in this scope}$
    133167\end{lstlisting}
    134168
    135169\section{\CFA-Style Enum}
    136170
    137 A \CFA enumeration is parameterized by a type specifying each enumerator's type.
    138 \CFA allows any object type for the enumerators, and values assigned to enumerators must be from the declared type.
     171\CFA supports C-Style enumeration using the same syntax and semantics for backwards compatibility.
     172\CFA also extends C-Style enumeration by adding a number of new features that bring enumerations inline with other modern programming languages.
     173
     174\subsection{Enumerator Typing}
     175
     176\CFA extends the enumeration by parameterizing the enumeration with a type for the enumerators, allowing enumerators to be assigned any values from the declared type.
    139177\begin{lstlisting}[label=lst:color]
    140 enum Colour( @char *@ ) { Red = "R", Green = "G", Blue = "B"  };
    141 \end{lstlisting}
    142 The type of @Colour@ is @char *@ and each enumerator is initialized with a C string.
    143 Only types with a defined ordering can be automatically initialized (see Section~\ref{s:AutoInitializable}).
     178enum( @char@ ) Currency { Dollar = '$\textdollar$', Euro = '$\texteuro$', Pound = '$\textsterling$'  };
     179enum( @double@ ) Planet { Venus = 4.87, Earth = 5.97, Mars = 0.642  }; // mass
     180enum( @char *@ ) Colour { Red = "red", Green = "green", Blue = "blue"  };
     181enum( @Currency@ ) Europe { Euro = '$\texteuro$', Pound = '$\textsterling$' }; // intersection
     182\end{lstlisting}
     183The types of the enumerators are @char@, @double@, and @char *@ and each enumerator is initialized with corresponding type values.
     184% Only types with a defined ordering can be automatically initialized (see Section~\ref{s:AutoInitializable}).
    144185
    145186% An instance of \CFA-enum (denoted as @<enum_instance>@) is a label for the defined enum name.
     
    151192A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
    152193\begin{lstlisting}
    153 enum Colour( char * ) @!@ { ... };
     194enum Weekday @!@ { /* as above */ };
     195enum Colour( char * ) @!@ { /* as above */ };
    154196\end{lstlisting}
    155197where the @'!'@ implies the enumerators are \emph{not} projected.
     
    158200% $$<qualified\_expression> := <enum\_type>.<enumerator>$$
    159201\begin{lstlisting}
    160 Colour colour = @Colour.@Red;   // qualification
     202Weekday weekday = @Weekday.Monday@;             $\C{// qualification}$
     203Colour colour = @Colour.@Red;
    161204colour = @Colour.@Blue;
    162205\end{lstlisting}
    163206
    164 \section{Enumeration Pseudo-functions}
    165 Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@. Instead, the call to functions will be substituted into other expressions in compilation time.
    166 
    167 \subsection{Enumerator Attributes}
    168 The attributes of an enumerator are accessed by pseudo-functions @position@, @value@, and @label@.
     207\subsection{Enumeration Pseudo-functions}
     208
     209Pseudo-functions are function-like operators that do not result in any run-time computations, i.e., like @sizeof@.
     210Often a call to a pseudo-function is substituted with information extracted from the symbol table at compilation time, like storage size or alignment associated with the underlying architecture..
     211
     212\subsubsection{Enumerator Attributes}
     213The attributes of an enumerator are accessed by pseudo-functions @position@, @value@, and @label@.
    169214\begin{lstlisting}
    170 int green_pos = @position@( Colour.Green );     // 1
    171 char * green_value = @value@( Colour.Green ); / "G"
    172 char * green_label = @label@( Colour.Green ); // "Green"
    173 \end{lstlisting}
    174 
    175 \subsection{enumerate()}
     215int green_pos = @position@( Colour.Green );     $\C{// 1}$
     216char * green_value = @value@( Colour.Green ); $\C{// "G"}$
     217char * green_label = @label@( Colour.Green ); $\C{// "Green"}$
     218\end{lstlisting}
     219
     220Enumeration Greek may have more or less enumerators than Letter, but the enumerator values must be from Letter.
     221Therefore, Greek enumerators are a subset of type Letter and are type compatible with enumeration Letter, but Letter enumerators are not type compatible with enumeration Greek.
     222
     223\subsubsection{\lstinline{enumerate()}}
     224
    176225\begin{lstlisting}[label=lst:c_switch]
    177226enum(int) C_ENUM { First, Second, Third = First, Fourth };
    178 int v(C_ENUM e) {
    179     switch( e ) {
    180         case First: return 0; break;
    181         case Second: return 1; break;
    182         // case Thrid: return 2; break;
    183         // case Fourth: return 3; break;
    184     };
    185 };
    186 \end{lstlisting}
    187 In the @C_ENUM@ example, @Third@ is an alias of @First@ and @Fourth@ is an alias of @Second@. Programmers cannot make case branches for @Third@ and @Fourth@ because the switch statement matches cases by the enumerator's value. Case First and Third, or Second and Fourth, has duplicate case values.
    188 
    189 @enumerate()@ is a pseudo-function that makes the switch statement match by an enumerator instead.
     227int v( C_ENUM e ) {
     228        switch( e ) {
     229                case First: return 0; break;
     230                case Second: return 1; break;
     231                // case Third: return 2; break;
     232                // case Fourth: return 3; break;
     233        };
     234};
     235\end{lstlisting}
     236In the @C_ENUM@ example, @Third@ is an alias of @First@ and @Fourth@ is an alias of @Second@.
     237Programmers cannot make case branches for @Third@ and @Fourth@ because the switch statement matches cases by the enumerator's value.
     238Case @First@ and @Third@, or @Second@ and @Fourth@, has duplicate case values.
     239
     240@enumerate()@ is a pseudo-function that makes the switch statement match by an enumerator instead.
    190241\begin{lstlisting}[label=lst:c_switch_enumerate]
    191242enum(double) C_ENUM { First, Second, Third = First, Fourth };
    192 C_ENUM variable_a = First, variable_b = Second, variable_c = Thrid, variable_d = Fourth;
    193 int v(C_ENUM e) { 
    194     switch( enumeratate( e ) ) {
    195         case First: return e; break;
    196         case Second: return value( e ); break;
    197         case Thrid: return label( e ); break;
    198         case Fourth: return position( e ); break;
    199     };
     243C_ENUM variable_a = First, variable_b = Second, variable_c = Third, variable_d = Fourth;
     244int v(C_ENUM e) {
     245        switch( enumeratate( e ) ) {
     246                case First: return e; break;
     247                case Second: return value( e ); break;
     248                case Third: return label( e ); break;
     249                case Fourth: return position( e ); break;
     250        };
    200251};
    201252p(variable_a); // 0
     
    205256\end{lstlisting}
    206257
     258
    207259\section{Enumeration Storage}
     260
    208261
    209262\subsection{Enumeration Variable}
     
    228281>>> label( Colour, 1) -> char *
    229282\end{lstlisting}
    230 @T@ represents the type declared in the \CFA enumeration defined and @char *@ in the example. 
     283@T@ represents the type declared in the \CFA enumeration defined and @char *@ in the example.
    231284These generated functions are $Companion Functions$, they take an $companion$ object and the position as parameters.
    232285
     286
    233287\subsection{Enumeration Data}
     288
    234289\begin{lstlisting}[label=lst:enumeration_backing_data]
    235290enum(T) E { ... };
    236291// backing data
    237 T* E_values;
    238 char** E_labels;
    239 \end{lstlisting}
    240 Storing values and labels as arrays can sometimes help support enumeration features. However, the data structures are the overhead for the programs. We want to reduce the memory usage for enumeration support by:
     292T * E_values;
     293char ** E_labels;
     294\end{lstlisting}
     295Storing values and labels as arrays can sometimes help support enumeration features.
     296However, the data structures are the overhead for the programs. We want to reduce the memory usage for enumeration support by:
    241297\begin{itemize}
    242     \item Only generates the data array if necessary
    243     \item The compilation units share the data structures. No extra overhead if the data structures are requested multiple times.
     298        \item Only generates the data array if necessary
     299        \item The compilation units share the data structures.
     300        No extra overhead if the data structures are requested multiple times.
    244301\end{itemize}
    245302
    246303
    247 \
    248304\section{Unification}
    249305
    250306\subsection{Enumeration as Value}
    251307\label{section:enumeration_as_value}
    252 An \CFA enumeration with base type T can be used seamlessly as T, without explicitly calling the pseudo-function value. 
     308An \CFA enumeration with base type T can be used seamlessly as T, without explicitly calling the pseudo-function value.
    253309\begin{lstlisting}[label=lst:implicit_conversion]
    254310char * green_value = Colour.Green; // "G"
    255 // Is equivalent to 
     311// Is equivalent to
    256312// char * green_value = value( Color.Green ); "G"
    257313\end{lstlisting}
    258314
     315
    259316\subsection{Unification Distance}
     317
    260318\begin{lstlisting}[label=lst:unification_distance_example]
    261319T_2 Foo(T1);
     
    265323@path(A, B)@ is a compiler concept that returns one of the following:
    266324\begin{itemize}
    267     \item Zero or 0, if and only if $A == B$.
    268     \item Safe, if B can be used as A without losing its precision, or B is a subtype of A.
    269     \item Unsafe, if B loses its precision when used as A, or A is a subtype of B.
    270     \item Infinite, if B cannot be used as A. A is not a subtype of B and B is not a subtype of A.
     325        \item Zero or 0, if and only if $A == B$.
     326        \item Safe, if B can be used as A without losing its precision, or B is a subtype of A.
     327        \item Unsafe, if B loses its precision when used as A, or A is a subtype of B.
     328        \item Infinite, if B cannot be used as A. A is not a subtype of B and B is not a subtype of A.
    271329\end{itemize}
    272330
     
    278336The arithmetic of distance is the following:
    279337\begin{itemize}
    280     \item $Zero + v= v$, for some value v.
    281     \item $Safe * k <  Unsafe$, for finite k.
    282     \item $Unsafe * k < Infinite$, for finite k.
    283     \item $Infinite + v = Infinite$, for some value v.
     338        \item $Zero + v= v$, for some value v.
     339        \item $Safe * k <  Unsafe$, for finite k.
     340        \item $Unsafe * k < Infinite$, for finite k.
     341        \item $Infinite + v = Infinite$, for some value v.
    284342\end{itemize}
    285343
     
    288346
    289347\subsection{Variable Overloading and Parameter Unification}
     348
    290349\CFA allows variable names to be overloaded. It is possible to overload a variable that has type T and an enumeration with type T.
    291350\begin{lstlisting}[label=lst:variable_overload]
     
    304363Similarly, functions can be overloaded with different signatures. \CFA picks the correct function entity based on the distance between parameter types and the arguments.
    305364\begin{lstlisting}[label=lst:function_overload]
    306 Colour green = Colour.Green; 
     365Colour green = Colour.Green;
    307366void foo(Colour c) { sout | "It is an enum"; } // First foo
    308367void foo(char * s) { sout | "It is a string"; } // Second foo
     
    326385% The @EnumInstType@ is convertible to other types.
    327386% A \CFA enumeration expression is implicitly \emph{overloaded} with its three different attributes: value, position, and label.
    328 % The \CFA compilers need to resolve an @EnumInstType@ as one of its attributes based on the current context. 
     387% The \CFA compilers need to resolve an @EnumInstType@ as one of its attributes based on the current context.
    329388
    330389% \begin{lstlisting}[caption={Null Context}, label=lst:null_context]
     
    379438% }
    380439% \end{lstlisting}
    381 % % The conversion can work backward: in restrictive cases, attributes of can be implicitly converted back to the EnumInstType. 
     440% % The conversion can work backward: in restrictive cases, attributes of can be implicitly converted back to the EnumInstType.
    382441% Backward conversion:
    383442% \begin{lstlisting}[caption={Unification Functions}, label=lst:unification_func_call]
     
    389448% \begin{lstlisting}[caption={Unification Functions}, label=lst:unification_func_call]
    390449% {
    391 %    Unification( EnumInstType<Colour>, int ) >>> label
     450%       Unification( EnumInstType<Colour>, int ) >>> label
    392451% }
    393452% \end{lstlisting}
    394453% @int@ can be unified with the label of Colour.
    395 % @5@ is a constant expression $\Rightarrow$ Compiler knows the value during the compilation $\Rightarrow$ turns it into 
     454% @5@ is a constant expression $\Rightarrow$ Compiler knows the value during the compilation $\Rightarrow$ turns it into
    396455% \begin{lstlisting}
    397456% {
    398 %    enum Colour colour = Colour.Green;
     457%       enum Colour colour = Colour.Green;
    399458% }
    400459% \end{lstlisting}
     
    411470% {
    412471%       enum T (int) { ... } // Declaration
    413 %       enum T t = 1; 
     472%       enum T t = 1;
    414473% }
    415474% \end{lstlisting}
     
    423482% return the FIRST enumeration constant that has the value 1, by searching through the values array
    424483% \end{enumerate}
    425 % The downside of the precedence rule: @EnumInstType@ $\Rightarrow$ @int ( value )@ $\Rightarrow$ @EnumInstType@ may return a different @EnumInstType@ because the value can be repeated and there is no way to know which one is expected $\Rightarrow$ want uniqueness 
     484% The downside of the precedence rule: @EnumInstType@ $\Rightarrow$ @int ( value )@ $\Rightarrow$ @EnumInstType@ may return a different @EnumInstType@ because the value can be repeated and there is no way to know which one is expected $\Rightarrow$ want uniqueness
    426485
    427486% \subsection{Casting}
     
    431490% (int) Foo.A;
    432491% \end{lstlisting}
    433 % The \CFA-compiler unifies @EnumInstType<int>@ with int, with returns @value( Foo.A )@, which has statically known value 10. In other words, \CFA-compiler is aware of a cast expression, and it forms the context for EnumInstType resolution. The expression with type @EnumInstType<int>@ can be replaced by the compile with a constant expression 10, and optionally discard the cast expression. 
     492% The \CFA-compiler unifies @EnumInstType<int>@ with int, with returns @value( Foo.A )@, which has statically known value 10. In other words, \CFA-compiler is aware of a cast expression, and it forms the context for EnumInstType resolution. The expression with type @EnumInstType<int>@ can be replaced by the compile with a constant expression 10, and optionally discard the cast expression.
    434493
    435494% \subsection{Value Conversion}
     
    445504% int j = value( Foo, a )
    446505% \end{lstlisting}
    447 % Similarly, the generated code for the third line is 
     506% Similarly, the generated code for the third line is
    448507% \begin{lstlisting}
    449508% char * j = label( Foo, a )
     
    455514
    456515\subsection{C Enumeration Rule}
    457 A C enumeration has an integral type. If not initialized, the first enumerator implicitly has the integral value 0, and other enumerators have a value equal to its $predecessor + 1$. 
     516A C enumeration has an integral type. If not initialized, the first enumerator implicitly has the integral value 0, and other enumerators have a value equal to its $predecessor + 1$.
    458517
    459518\subsection{Auto Initializable}
     
    478537Odd ?++( Odd t1 ) { return Odd( t1.i + 2); };
    479538\end{lstlisting}
    480 When the type of an enumeration is @AutoInitializable@, implicit initialization is available. 
     539When the type of an enumeration is @AutoInitializable@, implicit initialization is available.
    481540\begin{lstlisting}[label=lst:sample_auto_Initializable_usage]
    482541enum AutoInitUsage(Odd) {
     
    514573@alph@ is the iterating enumeration object, which returns the value of an @Alphabet@ in this context according to the precedence rule.
    515574
    516 \textbullet\ \CFA offers a shorthand for iterating all enumeration constants: 
     575\textbullet\ \CFA offers a shorthand for iterating all enumeration constants:
    517576\begin{lstlisting}[label=lst:range_functions]
    518577for ( Alphabet alph ) { sout | alph; }
     
    567626>>> 10 11 12 13 14 15 16 17 18
    568627\end{lstlisting}
    569 The first syntax is stepping to the next enumeration constant, which is the default stepping scheme if not explicitly specified. The second syntax, on the other hand, is to call @operator+=@ @one_type@ on the @value( s )@. Therefore, the second syntax is equivalent to 
     628The first syntax is stepping to the next enumeration constant, which is the default stepping scheme if not explicitly specified. The second syntax, on the other hand, is to call @operator+=@ @one_type@ on the @value( s )@. Therefore, the second syntax is equivalent to
    570629\begin{lstlisting}[label=lst:range_function_stepping_converted]
    571630for ( typeof( value(Sequence.A) ) s=value( Sequence.A ); s <= Sequence.D; s+=1  ) { sout | alph; }
     
    579638for ( char * alph; Alphabet )
    580639\end{lstlisting}
    581 This for-loop implicitly iterates every label of the enumeration, because a label is the only valid resolution to the ch with type @char *@ in this case.
     640This for-loop implicitly iterates every label of the enumeration, because a label is the only valid resolution to @ch@ with type @char *@ in this case.
    582641If the value can also be resolved as the @char *@, you might iterate the labels explicitly with the array iteration.
    583642\begin{lstlisting}[label=lst:range_functions_label_implicit]
     
    591650% \begin{lstlisting}
    592651% enum T( int, char * ) {
    593 %    a=42, b="Hello World"
     652%        a=42, b="Hello World"
    594653% };
    595654% \end{lstlisting}
    596 % The enum T declares two different types: int and char *. The enumerators of T hold values of one of the declared types. 
     655% The enum T declares two different types: int and char *. The enumerators of T hold values of one of the declared types.
    597656
    598657\subsection{Enumeration Inheritance}
     
    602661enum /* inferred */ Name2 { inline Name, Sue = "Sue", Tom = "Tom" };
    603662\end{lstlisting}
    604 \lstinline{Inline} allows Enumeration Name2 to inherit enumerators from Name1 by containment, and a Name enumeration is a subtype of enumeration Name2. An enumeration instance of type Name can be used where an instance of Name2 is expected. 
     663\lstinline{Inline} allows Enumeration Name2 to inherit enumerators from Name1 by containment, and a Name enumeration is a subtype of enumeration Name2. An enumeration instance of type Name can be used where an instance of Name2 is expected.
    605664\begin{lstlisting}[label=lst:EnumInline]
    606665Name Fred;
     
    610669If enumeration A declares @inline B@ in its enumeration body, enumeration A is the "inlining enum" and enumeration B is the "inlined enum".
    611670
    612 An enumeration can inline at most one other enumeration. The inline declaration must be placed before the first enumerator of the inlining enum. The inlining enum has all the enumerators from the inlined enum, with the same labels, values, and position. 
     671An enumeration can inline at most one other enumeration. The inline declaration must be placed before the first enumerator of the inlining enum. The inlining enum has all the enumerators from the inlined enum, with the same labels, values, and position.
    613672\begin{lstlisting}[label=lst:EnumInline]
    614673enum /* inferred */ Name2 { inline Name, Sue = "Sue", Tom = "Tom" };
     
    625684\begin{lstlisting}[label=lst:static_attr]
    626685enum( char * ) Colour {
    627     Red = "red", Blue = "blue", Green = "green" 
    628 };
    629 \end{lstlisting}
    630 An enumerator expression returns its enumerator value as a constant expression with no runtime cost. For example, @Colour.Red@ is equivalent to the constant expression "red", and \CFA finishes the expression evaluation before generating the corresponding C code. Applying a pseudo-function to a constant enumerator expression results in a constant expression as well. @value( Colour.Red )@, @position( Colour. Red )@, and @label( Colour.Red )@ are equivalent to constant expression with char * value "red", int value 0, and char * value "Red", respectively. 
     686        Red = "red", Blue = "blue", Green = "green"
     687};
     688\end{lstlisting}
     689An enumerator expression returns its enumerator value as a constant expression with no runtime cost. For example, @Colour.Red@ is equivalent to the constant expression "red", and \CFA finishes the expression evaluation before generating the corresponding C code. Applying a pseudo-function to a constant enumerator expression results in a constant expression as well. @value( Colour.Red )@, @position( Colour. Red )@, and @label( Colour.Red )@ are equivalent to constant expression with char * value "red", int value 0, and char * value "Red", respectively.
    631690
    632691\subsection{Runtime Attribute Expression and Weak Referenced Data}
     
    638697An enumeration variable c is equivalent to an integer variable with the value of @position( c )@ In Example~\ref{lst:dynamic_attr}, the value of enumeration variable c is unknown at compile time. In this case, the pseudo-function calls are reduced to expression that returns the enumerator values at runtime.
    639698
    640 \CFA stores the variables and labels in const arrays to provide runtime lookup for enumeration information.
     699\CFA stores the variables and labels in @const@ arrays to provide runtime lookup for enumeration information.
    641700
    642701\begin{lstlisting}[label=lst:attr_array]
     
    651710\end{lstlisting}
    652711
    653 To avoid unnecessary memory usage, the labels and values array are only generated as needed, and only generate once across all compilation units. By default, \CFA defers the declaration of the label and value arrays until an call to attribute function with a dynamic value. If an attribute function is never called on a dynamic value of an enumerator, the array will never be allocated. Once the arrays are created, all compilation units share a weak reference to the allocation array. 
     712To avoid unnecessary memory usage, the labels and values array are only generated as needed, and only generate once across all compilation units. By default, \CFA defers the declaration of the label and value arrays until an call to attribute function with a dynamic value. If an attribute function is never called on a dynamic value of an enumerator, the array will never be allocated. Once the arrays are created, all compilation units share a weak reference to the allocation array.
    654713
    655714\subsection{Enum Prelude}
     
    657716\begin{lstlisting}[label=lst:enum_func_dec]
    658717forall( T ) {
    659     unsigned position( unsigned );
    660     T value( unsigned );
    661     char * label( unsigned );
     718        unsigned position( unsigned );
     719        T value( unsigned );
     720        char * label( unsigned );
    662721}
    663722\end{lstlisting}
     
    670729forall(T)
    671730class EnumDecl {
    672     T* values;
    673     char** label;
     731        T* values;
     732        char** label;
    674733};
    675734\end{lstlisting}
     
    679738\begin{lstlisting}[label=lst:EnumInstType]
    680739class EnumInstType {
    681     EnumDecl enumDecl;
    682     int position;
     740        EnumDecl enumDecl;
     741        int position;
    683742};
    684743\end{lstlisting}
     
    700759% struct Companion {
    701760%       const T * const values;
    702 %        const char * label;
     761%                const char * label;
    703762%       int length;
    704763% };
     
    706765% \CFA generates companion objects, an instance of structure that encloses @necessary@ data to represent an enumeration. The size of the companion is unknown at the compilation time, and it "grows" in size to compensate for the @usage@.
    707766
    708 % The companion object is singleton across the compilation (investigation). 
     767% The companion object is singleton across the compilation (investigation).
    709768
    710769% \CFA generates the definition of companion functions.
     
    727786\begin{lstlisting}[label=lst:companion_trait]
    728787forall(T1) {
    729     trait Companion(otype T2<otype T1>) {
    730         T1 value((otype T2<otype T1> const &);
    731         int position(otype T2<otype T1> const &);
    732         char * label(otype T2<otype T1> const &);
    733     }
     788        trait Companion(otype T2<otype T1>) {
     789                T1 value((otype T2<otype T1> const &);
     790                int position(otype T2<otype T1> const &);
     791                char * label(otype T2<otype T1> const &);
     792        }
    734793}
    735794\end{lstlisting}
     
    743802\begin{lstlisting}
    744803enum(int) Weekday {
    745     Monday=10, Tuesday, ...
     804        Monday=10, Tuesday, ...
    746805};
    747806
     
    758817\subsection{User Define Enumeration Functions}
    759818
    760 Companion objects make extending features for \CFA enumeration easy. 
     819Companion objects make extending features for \CFA enumeration easy.
    761820\begin{lstlisting}[label=lst:companion_user_definition]
    762 char * charastic_string( Companion o, int position ) { 
    763         return sprintf( "Label: %s; Value: %s", label( o, position ), value( o, position) ); 
     821char * charastic_string( Companion o, int position ) {
     822        return sprintf( "Label: %s; Value: %s", label( o, position ), value( o, position) );
    764823}
    765824printf( charactic_string ( Color, 1 ) );
     
    776835Similarly, the user can work with the enumeration type itself: (see section ref...)
    777836\begin{lstlisting}[ label=lst:companion_user_definition]
    778 void print_enumerators ( Companion o ) { 
     837void print_enumerators ( Companion o ) {
    779838        for ( c : Companion o ) {
    780839                sout | label (c) | value( c ) ;
    781         } 
     840        }
    782841}
    783842print_enumerators( Colour );
     
    795854It ensures that the name of an enumerator is unique within the enumeration body, and checks if all values of the enumerator have the declaration type.
    796855If the declared type is not @AutoInitializable@, \CFA rejects the enumeration definition.
    797 Otherwise, it attempts to initialize enumerators with the enumeration initialization pattern. (a reference to a future initialization pattern section) 
     856Otherwise, it attempts to initialize enumerators with the enumeration initialization pattern. (a reference to a future initialization pattern section)
    798857
    799858\begin{lstlisting}[label=lst:init]
     
    803862T ?+?( T & lhs, T & rhs ) { ... };
    804863
    805 enum (T) Sample { 
    806         Zero: 0 /* zero_t */, 
     864enum (T) Sample {
     865        Zero: 0 /* zero_t */,
    807866        One: Zero + 1 /* ?+?( Zero, one_t ) */ , ...
    808867};
     
    826885\subsection{Qualified Expression}
    827886
    828 \CFA uses qualified expression to address the scoping of \CFA-enumeration. 
     887\CFA uses qualified expression to address the scoping of \CFA-enumeration.
    829888\begin{lstlisting}[label=lst:qualified_expression]
    830889aggregation_name.field;
     
    837896
    838897\subsection{\lstinline{with} Clause/Statement}
     898
    839899Instead of qualifying an enumeration expression every time, the @with@ can be used to expose enumerators to the current scope, making them directly accessible.
    840900\begin{lstlisting}[label=lst:declaration]
     
    842902enum Animal( int ) { Cat=10, Dog=20 };
    843903with ( Color, Animal ) {
    844     char * red_string = Red; // value( Color.Red )
    845     int cat = Cat; // value( Animal.Cat )
     904        char * red_string = Red; // value( Color.Red )
     905        int cat = Cat; // value( Animal.Cat )
    846906}
    847907\end{lstlisting}
     
    851911enum RGB( int ) { Red=0, Green=1, Blue=2 };
    852912with ( Color, RGB ) {
    853     // int red = Red;
     913        // int red = Red;
    854914}
    855915\end{lstlisting}
     
    865925The declaration \CFA-enumeration variable has the same syntax as the C-enumeration. Internally, such a variable will be represented as an EnumInstType.
    866926
     927\section{Related Work}
     928
     929Enumerations exist in many popular programming languages, e.g., Pascal, Ada, \Csharp, \CC, Go, Java, Modula-3, Rust, Swift, Python, and Algebraic data type in functional programming.
     930There are a large set of overlapping features for all the languages, but each language has its own unique restrictions and extensions.
     931
     932\subsection{Pascal}
     933
     934\subsection{Ada}
     935
     936\subsection{\Csharp}
     937
     938\subsection{\CC}
     939
     940Because \CC is backwards compatible with C, it inherited C's enumerations, except there is no implicit conversion from an integral value to an enumeration;
     941hence, the values in a \CC enumeration can only be its enumerators.
     942
     943\CC{11} extended enumeration with a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), where the enumerators are local to the enumeration and are accessed using type qualification, e.g., @Weekday::Monday@.
     944\CC{20} supports unscoped access with a \lstinline[language=c++]{using enum} declaration.
     945
     946For both unscoped and scoped enumerations, the underlying type is an implementation-defined integral type that is large enough to hold all enumerated values; it does not have to be the smallest possible type.
     947The underlying integral type can be explicitly specified:
     948\begin{lstlisting}[language=c++,{moredelim=**[is][\color{red}]{@}{@}}]
     949enum class RGB : @long@ { Red, Green, Blue };
     950enum class rgb : @char@ { Red = 'r', Green = 'g', Blue = 'b' };
     951enum class srgb : @signed char@ { Red = -1, Green = 0, Blue = 1 };
     952\end{lstlisting}
     953
     954\subsection{Go}
     955
     956\subsection{Java}
     957
     958\subsection{Modula-3}
     959
     960\subsection{Rust}
     961
     962\subsection{Swift}
     963
     964\subsection{Python}
     965
     966\subsection{Algebraic Data Type}
    867967
    868968\end{document}
  • doc/uC++toCFA/Makefile

    rc75b30a r32490deb  
    88BibTeX = BIBINPUTS=../bibliography: && export BIBINPUTS && bibtex
    99
    10 MAKEFLAGS = --no-print-directory --silent #
     10MAKEFLAGS = --no-print-directory # --silent
    1111VPATH = ${Build} ${Figures}
    1212
  • doc/uC++toCFA/uC++toCFA.tex

    rc75b30a r32490deb  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Oct 15 23:09:58 2023
    14 %% Update Count     : 5926
     13%% Last Modified On : Thu Jan 11 14:46:14 2024
     14%% Update Count     : 5942
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    428428\begin{uC++}
    429429struct S {
    430         int i = 0;
     430        int i = 0;  // cheat, implicit default constructor
    431431        int setter( int j ) { int t = i; i = j; return t; }
    432432        int getter() { return i; }
     
    434434
    435435S s;
    436 @s.@setter( 3 );  // object-oriented call
     436@s.@setter( 3 );  // object-oriented calls
    437437int k = @s.@getter();
    438438\end{uC++}
     
    442442        int i;
    443443};
    444 void ?{}( S & s ) { s.i = 0; }
     444void ?{}( S & s ) { s.i = 0; } // explicit default constructor
    445445int setter( @S & s,@ int j ) @with(s)@ { int t = i; i = j; return t; }
    446446int getter( @S & s@ ) @with(s)@ { return i; }
    447447S s;
    448 setter( @s,@ 3 );  // normal routine call
     448setter( @s,@ 3 );  // normal routine calls
    449449int k = getter( @s@ );
    450450\end{cfa}
     
    458458\begin{tabular}{l|l}
    459459\begin{uC++}
     460
    460461struct S {
    461462        int i;
    462         S( int i ) { S::i = i; cout << S::i << endl; }
    463 };
    464 @uNoCtor<S>@ s[10];
     463        S( int i ) { S::i = i; cout << "ctor " << S::i << endl; }
     464        ~S() { S::i = i; cout << "dtor " << S::i << endl; }
     465};
    465466int main() {
    466         for ( int i = 0; i < 10; i += 1 ) {
    467                 s[i].ctor( i );
    468         }
    469         for ( int i = 0; i < 10; i += 1 ) {
    470                 cout << s[i]@->@i << endl;
    471         }
    472 }
    473 \end{uC++}
    474 &
    475 \begin{cfa}
     467        enum { N = 5 };
     468        @uNoCtor<S>@ s[N];   // no constructor calls
     469        for ( int i = 0; i < N; i += 1 ) @s[i].ctor( i )@;
     470        for ( int i = 0; i < N; i += 1 ) cout << s[i]@->@i << endl;
     471}
     472\end{uC++}
     473&
     474\begin{cfa}
     475#include @<raii.hfa>@          // uninit
    476476struct S {
    477477        int i;
    478478};
    479 void ?{}( S & s, int i ) { s.i = i; sout | s.i; }
    480 S s[10] @$\color{red}@$= {}@;
     479void ?{}( S & s, int i ) { s.i = i; sout | "ctor" | s.i; }
     480void ^?{}( S & s ) { sout | "dtor" | s.i; }
    481481int main() {
    482         for ( i; 10 ) {
    483                 ?{}( s[i], i );  // call constructor
    484         }
    485         for ( i; 10 ) {
    486                 sout | s[i]@.@i; // dot not arrow
    487         }
     482        enum { N = 5 };
     483        @uninit(S)@ s[N];   // no constructor calls
     484        for ( i; N ) @s[i]{ i }@;
     485        for ( i; N ) sout | s[i]@.@i;
    488486}
    489487\end{cfa}
  • doc/user/user.tex

    rc75b30a r32490deb  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sun Jan 14 17:27:41 2024
    14 %% Update Count     : 5764
     13%% Last Modified On : Tue Jan 30 09:02:41 2024
     14%% Update Count     : 6046
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4646%\input{common}                                                                                 % common CFA document macros
    4747\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
     48\urlstyle{sf}
    4849\usepackage{breakurl}
    4950
     
    163164
    164165\Index*[C++]{\CC{}}~\cite{c++:v1} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
    165 However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that are difficult to update, and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
     166However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that are difficult to update, and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C code-base.
    166167In contrast, \CFA has 30 years of hindsight and a clean starting point.
    167168
     
    200201\end{center}
    201202While \CFA I/O \see{\VRef{s:StreamIOLibrary}} looks similar to \Index*[C++]{\CC{}}, there are important differences, such as automatic spacing between variables and an implicit newline at the end of the expression list, similar to \Index*{Python}~\cite{Python}.
     203In general, \CFA programs are 10\% to 30\% shorter than their equivalent C/\CC counterparts.
    202204
    203205
     
    218220Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    219221For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is the only language of choice.
    220 The TIOBE index~\cite{TIOBE} for February 2021 ranks the top six most \emph{popular} programming languages as C 17.4\%, \Index*{Java} 12\%, Python 12\%, \Index*[C++]{\CC{}} 7.6\%, \Csharp 4\%, Visual Basic 3.8\% = 56.8\%, where the next 50 languages are less than 2\% each, with a long tail.
     222The TIOBE index~\cite{TIOBE} for February 2023 ranks the top six most \emph{popular} programming languages as C 17.4\%, \Index*{Java} 12\%, Python 12\%, \Index*[C++]{\CC{}} 7.6\%, \Csharp 4\%, Visual Basic 3.8\% = 56.8\%, where the next 50 languages are less than 2\% each, with a long tail.
    221223The top 4 rankings over the past 35 years are:
    222224\begin{center}
     
    238240however, it largely extended the C language, and did not address many of C's existing problems.\footnote{%
    239241Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
    240 \Index*{Fortran}~\cite{Fortran08}, \Index*{Cobol}~\cite{Cobol14}, and \Index*{Ada}~\cite{Ada12} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
     242\Index*{Fortran}~\cite{Fortran08}, \Index*{Cobol}~\cite{Cobol14}, and \Index*{Ada}~\cite{Ada16} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
    241243\Index*{Java}~\cite{Java8}, \Index*{Go}~\cite{Go}, \Index*{Rust}~\cite{Rust} and \Index*{D}~\cite{D} are examples of the revolutionary approach for modernizing C/\CC, resulting in a new language rather than an extension of the descendent.
    242244These languages have different syntax and semantics from C, do not interoperate directly with C, and are not systems languages because of restrictive memory-management or garbage collection.
     
    263265% extending the C type system with parametric polymorphism and overloading, as opposed to the \Index*[C++]{\CC{}} approach of object-oriented extensions.
    264266\CFA{}\hspace{1pt}'s polymorphism was originally formalized by \Index*{Glen Ditchfield}\index{Ditchfield, Glen}~\cite{Ditchfield92}, and first implemented by \Index*{Richard Bilson}\index{Bilson, Richard}~\cite{Bilson03}.
    265 However, at that time, there was little interesting in extending C, so work did not continue.
     267However, at that time, there was little interest in extending C, so work did not continue.
    266268As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of the legacy code-base, so the \CFA project was restarted in 2015.
    267269
     
    272274\CFA is designed to integrate directly with existing C programs and libraries.
    273275The most important feature of \Index{interoperability} is using the same \Index{calling convention}s, so there is no complex interface or overhead to call existing C routines.
    274 This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features.
     276This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of software features.
    275277Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    276278Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at zero or very low cost.
     
    320322However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.
    321323For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
    322 Whereas, \CFA wraps each of these routines into one overloaded name ©abs©:
    323 \begin{cfa}
    324 char ®abs®( char );
    325 extern "C" { int ®abs®( int ); } §\C{// use default C routine for int
    326 long int ®abs®( long int );
    327 long long int ®abs®( long long int );
    328 float ®abs®( float );
    329 double ®abs®( double );
    330 long double ®abs®( long double );
    331 float _Complex ®abs®( float _Complex );
    332 double _Complex ®abs®( double _Complex );
    333 long double _Complex ®abs®( long double _Complex );
     324Whereas, \CFA wraps these routines into one overloaded name ©abs©:
     325\begin{cfa}
     326unsigned char ®abs®( signed char );                             §\C[3.5in]{// no C equivalent}§
     327extern "C" { int ®abs®( int ); }                                §\C{// C abs
     328unsigned long int ®abs®( long int );                    §\C{// C labs}§
     329unsigned long long int ®abs®( long long int );  §\C{// C llabs}§
     330float ®abs®( float );                                                   §\C{// C fabsf}§
     331double ®abs®( double );                                                 §\C{// C fabs}§
     332long double ®abs®( long double );                               §\C{// C fabsl}§
     333float _Complex ®abs®( float _Complex );                 §\C{// C cabsf}§
     334double _Complex ®abs®( double _Complex );               §\C{// C cabs}§
     335long double _Complex ®abs®( long double _Complex ); §\C{// C cabsl}\CRT§
    334336\end{cfa}
    335337The problem is a \Index{name clash} between the C name ©abs© and the \CFA names ©abs©, resulting in two name linkages\index{C linkage}: ©extern "C"© and ©extern "Cforall"© (default).
     
    339341
    340342This example illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
    341 The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    342 Hence, knowing the name ©abs© is sufficient to apply it to any type where it is applicable.
     343The name ``©abs©'' evokes the notion of absolute value and many mathematical types provide the notion of absolute value.
     344Hence, knowing the name ©abs© is sufficient to apply it to any applicable type.
    343345The time savings and safety of using one name uniformly versus $N$ unique names cannot be underestimated.
    344346
    345347
    346348\section{\CFA Compilation}
     349
     350\CFA is a \newterm{transpiler}, meaning it reads in a programming language (\CFA) as input and generates another programming language (C) as output, whereas a \newterm{compiler} reads in a programming language and generates assembler/machine code.
     351Hence, \CFA is like the C preprocessor modifying a program and sending it on to another step for further transformation.
     352The order of transformation is C preprocessor, \CFA, and finally GNU C compiler, which also has a number of transformation steps, such as assembler and linker.
    347353
    348354The command ©cfa© is used to compile a \CFA program and is based on the \Index{GNU} \Indexc{gcc} command, \eg:
     
    444450which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
    445451
    446 The \CFA translator has multiple steps.
    447 The following flags control how the translator works, the stages run, and printing within a stage.
     452The \CFA \Index{transpiler} has multiple internal steps.
     453The following flags control how the \CFA transpiler works, the stages run, and printing within a stage.
    448454The majority of these flags are used by \CFA developers, but some are occasionally useful to programmers.
    449 Each option must be escaped with \Indexc{-XCFA}\index{translator option!-XCFA@{©-XCFA©}} to direct it to the compiler step, similar to the ©-Xlinker© flag for the linker, \eg:
     455Each option must be escaped with \Indexc{-XCFA}\index{transpiler option!-XCFA@{©-XCFA©}} to direct it to the \CFA compilation step, similar to the ©-Xlinker© flag for the linker, \eg:
    450456\begin{lstlisting}[language=sh]
    451457cfa §test§.cfa -CFA -XCFA -p # print translated code without printing the standard prelude
     
    458464\begin{description}[topsep=5pt,itemsep=0pt,parsep=0pt]
    459465\item
    460 \Indexc{-c}\index{translator option!-c@{©-c©}}, \Indexc{--colors}\index{translator option!--colors@{©--colors©}} \, diagnostic color: ©never©, ©always©, \lstinline[deletekeywords=auto]{auto}
    461 \item
    462 \Indexc{-g}\index{translator option!-g@{©-g©}}, \Indexc{--gdb}\index{translator option!--gdb@{©--gdb©}} \, wait for gdb to attach
    463 \item
    464 \Indexc{-h}\index{translator option!-h@{©-h©}}, \Indexc{--help}\index{translator option!--help@{©--help©}} \, print translator help message
    465 \item
    466 \Indexc{-i}\index{translator option!-i@{©-i©}}, \Indexc{--invariant}\index{translator option!--invariant@{©--invariant©}} \, invariant checking during AST passes
    467 \item
    468 \Indexc{-l}\index{translator option!-l@{©-l©}}, \Indexc{--libcfa}\index{translator option!--libcfa@{©--libcfa©}} \, generate ©libcfa.c©
    469 \item
    470 \Indexc{-L}\index{translator option!-L@{©-L©}}, \Indexc{--linemarks}\index{translator option!--linemarks@{©--linemarks©}} \, generate line marks
    471 \item
    472 \Indexc{-m}\index{translator option!-m@{©-m©}}, \Indexc{--no-main}\index{translator option!--no-main@{©--no-main©}} \, do not replace main
    473 \item
    474 \Indexc{-N}\index{translator option!-N@{©-N©}}, \Indexc{--no-linemarks}\index{translator option!--no-linemarks@{©--no-linemarks©}} \, do not generate line marks
    475 \item
    476 \Indexc{-n}\index{translator option!-n@{©-n©}}, \Indexc{--no-prelude}\index{translator option!--no-prelude@{©--no-prelude©}} \, do not read prelude
    477 \item
    478 \Indexc{-p}\index{translator option!-p@{©-p©}}, \Indexc{--prototypes}\index{translator option!--prototypes@{©--prototypes©}} \, do not generate prelude prototypes $\Rightarrow$ prelude not printed
    479 \item
    480 \Indexc{-d}\index{translator option!-d@{©-d©}}, \Indexc{--deterministic-out}\index{translator option!--deterministic-out@{©--deterministic-out©}} \, only print deterministic output
    481 \item
    482 \Indexc{-P}\index{translator option!-P@{©-P©}}, \Indexc{--print}\index{translator option!--print@{©--print©}} \, one of:
     466\Indexc{-c}\index{transpiler option!-c@{©-c©}}, \Indexc{--colors}\index{transpiler option!--colors@{©--colors©}} \, diagnostic color: ©never©, ©always©, \lstinline[deletekeywords=auto]{auto}
     467\item
     468\Indexc{-g}\index{transpiler option!-g@{©-g©}}, \Indexc{--gdb}\index{transpiler option!--gdb@{©--gdb©}} \, wait for gdb to attach
     469\item
     470\Indexc{-h}\index{transpiler option!-h@{©-h©}}, \Indexc{--help}\index{transpiler option!--help@{©--help©}} \, print transpiler help message
     471\item
     472\Indexc{-i}\index{transpiler option!-i@{©-i©}}, \Indexc{--invariant}\index{transpiler option!--invariant@{©--invariant©}} \, invariant checking during AST passes
     473\item
     474\Indexc{-l}\index{transpiler option!-l@{©-l©}}, \Indexc{--libcfa}\index{transpiler option!--libcfa@{©--libcfa©}} \, generate ©libcfa.c©
     475\item
     476\Indexc{-L}\index{transpiler option!-L@{©-L©}}, \Indexc{--linemarks}\index{transpiler option!--linemarks@{©--linemarks©}} \, generate line marks
     477\item
     478\Indexc{-m}\index{transpiler option!-m@{©-m©}}, \Indexc{--no-main}\index{transpiler option!--no-main@{©--no-main©}} \, do not replace main
     479\item
     480\Indexc{-N}\index{transpiler option!-N@{©-N©}}, \Indexc{--no-linemarks}\index{transpiler option!--no-linemarks@{©--no-linemarks©}} \, do not generate line marks
     481\item
     482\Indexc{-n}\index{transpiler option!-n@{©-n©}}, \Indexc{--no-prelude}\index{transpiler option!--no-prelude@{©--no-prelude©}} \, do not read prelude
     483\item
     484\Indexc{-p}\index{transpiler option!-p@{©-p©}}, \Indexc{--prototypes}\index{transpiler option!--prototypes@{©--prototypes©}} \, do not generate prelude prototypes $\Rightarrow$ prelude not printed
     485\item
     486\Indexc{-d}\index{transpiler option!-d@{©-d©}}, \Indexc{--deterministic-out}\index{transpiler option!--deterministic-out@{©--deterministic-out©}} \, only print deterministic output
     487\item
     488\Indexc{-P}\index{transpiler option!-P@{©-P©}}, \Indexc{--print}\index{transpiler option!--print@{©--print©}} \, one of:
    483489\begin{description}[topsep=0pt,itemsep=0pt,parsep=0pt]
    484490\item
    485 \Indexc{ascodegen}\index{translator option!-P@{©-P©}!©ascodegen©}\index{translator option!--print@{©-print©}!©ascodegen©} \, print AST as codegen rather than AST
    486 \item
    487 \Indexc{asterr}\index{translator option!-P@{©-P©}!©asterr©}\index{translator option!--print@{©-print©}!©asterr©} \, print AST on error
    488 \item
    489 \Indexc{declstats}\index{translator option!-P@{©-P©}!©declstats©}\index{translator option!--print@{©-print©}!©declstats©} \, print code property statistics
    490 \item
    491 \Indexc{parse}\index{translator option!-P@{©-P©}!©parse©}\index{translator option!--print@{©-print©}!©parse©} \, print yacc (parsing) debug information
    492 \item
    493 \Indexc{pretty}\index{translator option!-P@{©-P©}!©pretty©}\index{translator option!--print@{©-print©}!©pretty©} \, prettyprint for ©ascodegen© flag
    494 \item
    495 \Indexc{rproto}\index{translator option!-P@{©-P©}!©rproto©}\index{translator option!--print@{©-print©}!©rproto©} \, resolver-proto instance
    496 \item
    497 \Indexc{rsteps}\index{translator option!-P@{©-P©}!©rsteps©}\index{translator option!--print@{©-print©}!©rsteps©} \, print resolver steps
    498 \item
    499 \Indexc{ast}\index{translator option!-P@{©-P©}!©ast©}\index{translator option!--print@{©-print©}!©ast©} \, print AST after parsing
    500 \item
    501 \Indexc{excpdecl}\index{translator option!-P@{©-P©}!©excpdecl©}\index{translator option!--print@{©-print©}!©excpdecl©} \, print AST after translating exception decls
    502 \item
    503 \Indexc{symevt}\index{translator option!-P@{©-P©}!©symevt©}\index{translator option!--print@{©-print©}!©symevt©} \, print AST after symbol table events
    504 \item
    505 \Indexc{expralt}\index{translator option!-P@{©-P©}!©expralt©}\index{translator option!--print@{©-print©}!©expralt©} \, print AST after expressions alternatives
    506 \item
    507 \Indexc{valdecl}\index{translator option!-P@{©-P©}!©valdecl©}\index{translator option!--print@{©-print©}!©valdecl©} \, print AST after declaration validation pass
    508 \item
    509 \Indexc{bresolver}\index{translator option!-P@{©-P©}!©bresolver©}\index{translator option!--print@{©-print©}!©bresolver©} \, print AST before resolver step
    510 \item
    511 \Indexc{expranly}\index{translator option!-P@{©-P©}!©expranly©}\index{translator option!--print@{©-print©}!©expranly©} \, print AST after expression analysis
    512 \item
    513 \Indexc{ctordtor}\index{translator option!-P@{©-P©}!©ctordtor©}\index{translator option!--print@{©-print©}!©ctordtor©} \, print AST after ctor/dtor are replaced
    514 \item
    515 \Indexc{tuple}\index{translator option!-P@{©-P©}!©tuple©}\index{translator option!--print@{©-print©}!©tuple©} \, print AST after tuple expansion
    516 \item
    517 \Indexc{instgen}\index{translator option!-P@{©-P©}!©instgen©}\index{translator option!--print@{©-print©}!©instgen©} \, print AST after instantiate generics
    518 \item
    519 \Indexc{bbox}\index{translator option!-P@{©-P©}!©bbox©}\index{translator option!--print@{©-print©}!©bbox©} \, print AST before box pass
    520 \item
    521 \Indexc{bcodegen}\index{translator option!-P@{©-P©}!©bcodegen©}\index{translator option!--print@{©-print©}!©bcodegen©} \, print AST before code generation
     491\Indexc{ascodegen}\index{transpiler option!-P@{©-P©}!©ascodegen©}\index{transpiler option!--print@{©-print©}!©ascodegen©} \, print AST as codegen rather than AST
     492\item
     493\Indexc{asterr}\index{transpiler option!-P@{©-P©}!©asterr©}\index{transpiler option!--print@{©-print©}!©asterr©} \, print AST on error
     494\item
     495\Indexc{declstats}\index{transpiler option!-P@{©-P©}!©declstats©}\index{transpiler option!--print@{©-print©}!©declstats©} \, print code property statistics
     496\item
     497\Indexc{parse}\index{transpiler option!-P@{©-P©}!©parse©}\index{transpiler option!--print@{©-print©}!©parse©} \, print yacc (parsing) debug information
     498\item
     499\Indexc{pretty}\index{transpiler option!-P@{©-P©}!©pretty©}\index{transpiler option!--print@{©-print©}!©pretty©} \, prettyprint for ©ascodegen© flag
     500\item
     501\Indexc{rproto}\index{transpiler option!-P@{©-P©}!©rproto©}\index{transpiler option!--print@{©-print©}!©rproto©} \, resolver-proto instance
     502\item
     503\Indexc{rsteps}\index{transpiler option!-P@{©-P©}!©rsteps©}\index{transpiler option!--print@{©-print©}!©rsteps©} \, print resolver steps
     504\item
     505\Indexc{ast}\index{transpiler option!-P@{©-P©}!©ast©}\index{transpiler option!--print@{©-print©}!©ast©} \, print AST after parsing
     506\item
     507\Indexc{excpdecl}\index{transpiler option!-P@{©-P©}!©excpdecl©}\index{transpiler option!--print@{©-print©}!©excpdecl©} \, print AST after translating exception decls
     508\item
     509\Indexc{symevt}\index{transpiler option!-P@{©-P©}!©symevt©}\index{transpiler option!--print@{©-print©}!©symevt©} \, print AST after symbol table events
     510\item
     511\Indexc{expralt}\index{transpiler option!-P@{©-P©}!©expralt©}\index{transpiler option!--print@{©-print©}!©expralt©} \, print AST after expressions alternatives
     512\item
     513\Indexc{valdecl}\index{transpiler option!-P@{©-P©}!©valdecl©}\index{transpiler option!--print@{©-print©}!©valdecl©} \, print AST after declaration validation pass
     514\item
     515\Indexc{bresolver}\index{transpiler option!-P@{©-P©}!©bresolver©}\index{transpiler option!--print@{©-print©}!©bresolver©} \, print AST before resolver step
     516\item
     517\Indexc{expranly}\index{transpiler option!-P@{©-P©}!©expranly©}\index{transpiler option!--print@{©-print©}!©expranly©} \, print AST after expression analysis
     518\item
     519\Indexc{ctordtor}\index{transpiler option!-P@{©-P©}!©ctordtor©}\index{transpiler option!--print@{©-print©}!©ctordtor©} \, print AST after ctor/dtor are replaced
     520\item
     521\Indexc{tuple}\index{transpiler option!-P@{©-P©}!©tuple©}\index{transpiler option!--print@{©-print©}!©tuple©} \, print AST after tuple expansion
     522\item
     523\Indexc{instgen}\index{transpiler option!-P@{©-P©}!©instgen©}\index{transpiler option!--print@{©-print©}!©instgen©} \, print AST after instantiate generics
     524\item
     525\Indexc{bbox}\index{transpiler option!-P@{©-P©}!©bbox©}\index{transpiler option!--print@{©-print©}!©bbox©} \, print AST before box pass
     526\item
     527\Indexc{bcodegen}\index{transpiler option!-P@{©-P©}!©bcodegen©}\index{transpiler option!--print@{©-print©}!©bcodegen©} \, print AST before code generation
    522528\end{description}
    523529\item
    524530\Indexc{--prelude-dir} <directory> \, prelude directory for debug/nodebug
    525531\item
    526 \Indexc{-S}\index{translator option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{translator option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information: ©counters©, ©heap©, ©time©, ©all©, ©none©
    527 \item
    528 \Indexc{-t}\index{translator option!-t@{©-t©}}, \Indexc{--tree}\index{translator option!--tree@{©--tree©}} build in tree
     532\Indexc{-S}\index{transpiler option!-S@{©-S©}!©counters,heap,time,all,none©}, \Indexc{--statistics}\index{transpiler option!--statistics@{©--statistics©}!©counters,heap,time,all,none©} <option-list> \, enable profiling information: ©counters©, ©heap©, ©time©, ©all©, ©none©
     533\item
     534\Indexc{-t}\index{transpiler option!-t@{©-t©}}, \Indexc{--tree}\index{transpiler option!--tree@{©--tree©}} build in tree
    529535\end{description}
    530536
     
    540546\end{cfa}
    541547Existing C programs with keyword clashes can be converted by prefixing the keyword identifiers with double backquotes, and eventually the identifier name can be changed to a non-keyword name.
    542 \VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files \see{\VRef{s:StandardHeaders}} can be handled using preprocessor \newterm{interposition}: ©#include_next© and ©-I filename©.
    543 Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is a seamless programming-experience.
     548\VRef[Figure]{f:HeaderFileInterposition} shows how clashes in existing C header-files \see{\VRef{s:StandardHeaders}} can be handled using preprocessor \newterm{interposition}: ©#include_next© and command-line ©-I filename©.
     549Several common C header-files with keyword clashes are fixed in the standard \CFA header-library, so there is largely a seamless programming-experience.
    544550
    545551\begin{figure}
     
    591597the type suffixes ©U©, ©L©, \etc may start with an underscore ©1_U©, ©1_ll© or ©1.0E10_f©.
    592598\end{enumerate}
    593 It is significantly easier to read and enter long constants when they are broken up into smaller groupings (many cultures use comma and/or period among digits for the same purpose).
     599It is significantly easier to read and enter long constants when they are broken up into smaller groupings (most cultures use comma and/or period among digits for the same purpose).
    594600This extension is backwards compatible, matches with the use of underscore in variable names, and appears in \Index*{Ada} and \Index*{Java} 8.
    595601\CC uses the single quote (©'©) as a separator, restricted within a sequence of digits, \eg ©0xaa©©'©©ff©, ©3.141©©'©©592E1©©'©©1©.
     602However, the drawback of the \CC approach is difficults parsing for IDEs between character and numeric constants, as quotes are no longer balanced (©'x'© and ©3.14©©'©©159©).
    596603
    597604
    598605\section{Exponentiation Operator}
    599606
    600 C, \CC, and Java (and other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
     607C, \CC, and Java (and other programming languages) have \emph{no} exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
    601608\CFA extends the basic operators with the exponentiation operator ©?©\R{©\\©}©?©\index{?\\?@©?@\@?©} and ©?©\R{©\\©}©=?©\index{?\\=?@©@\@=?©}, as in, ©x ©\R{©\\©}© y© and ©x ©\R{©\\©}©= y©, which means $x^y$ and $x \leftarrow x^y$.
    602609The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©(w * (((int)x) \ ((int)y))) * z©.
    603610
    604611There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    605 Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication ($O(\log y)$ multiplies or shifting if the exponent is 2).
     612Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication ($O(\log y)$ or shifting if the exponent is 2).
    606613Overflow for a large exponent or negative exponent returns zero.
    607614Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
     
    620627T ?®\®?( T ep, unsigned long int y );
    621628\end{cfa}
    622 A user type ©T© must define multiplication, one (©1©), and ©*©.
     629A user type ©T© must define one (©1©), and multiplication (©*©) \see{\VRef{s:Operator}}.
    623630
    624631
     
    631638\subsection{\texorpdfstring{\LstKeywordStyle{if} / \LstKeywordStyle{while} Statement}{if / while Statement}}
    632639
    633 The \Indexc{if}/\Indexc{while} expression allows declarations, similar to \Indexc{for} declaration expression.\footnote{
     640The \Indexc{if} and \Indexc{while} expressions are extended with declarations, similar to the \Indexc{for} declaration expression.\footnote{
    634641Declarations in the \Indexc{do}-©while© condition are not useful because they appear after the loop body.}
    635642\begin{cfa}
     
    653660\label{s:caseClause}
    654661
    655 C restricts a \Indexc{case} clause in \Indexc{switch} statement to a single value.
     662C restricts the \Indexc{case} clause in a \Indexc{switch} statement to a single value.
    656663For multiple ©case© clauses prefixing a statement within the ©switch© statement, it is necessary to have multiple ©case© clauses rather than multiple values.
    657664Requiring a ©case© clause for each value is not in the spirit of brevity normally associated with C.
     
    688695\end{tabular}
    689696\end{cquote}
    690 In addition, subranges are allowed to specify case values.
     697In addition, subranges are allowed to specify a contiguous set of case values.
    691698\begin{cquote}
    692699\begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{\hspace{2em}}l@{}}
     
    801808\end{cfa}
    802809This situation is better handled by a list of case values \see{\VRef{s:caseClause}}.
    803 While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from most programming languages with a ©switch© statement.
    804 Hence, default fall-through semantics results in a many programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
     810
     811While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive for many programmers and is different from most programming languages with a ©switch© statement.
     812Hence, default fall-through semantics results in programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
    805813
    806814\item
     
    819827The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    820828There are few arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    821 
    822829This C idiom is known as ``\Index*{Duff's device}''~\cite{Duff83}, from this example:
    823830\begin{cfa}
     
    9961003with the current \Indexc{switch}/\Indexc{choose} statement.
    9971004
     1005
     1006\subsection{Loop Control}
     1007
     1008Looping a fixed number of times, possibly with a loop index, occurs frequently.
     1009\CFA condenses simply looping to facilitate coding speed and safety~\see{examples in \VRef[Figure]{f:LoopControlExamples}}.
     1010
     1011The \Indexc{for}, \Indexc{while}, and \Indexc{do} loop-control are extended to allow an empty conditional, which implies a comparison value of ©1© (true).
     1012\begin{cfa}
     1013while ( ®/* empty */®  )                                §\C{// while ( true )}§
     1014for ( ®/* empty */®  )                                  §\C{// for ( ; true; )}§
     1015do ... while ( ®/* empty */®  )                 §\C{// do ... while ( true )}§
     1016\end{cfa}
     1017
    9981018\begin{figure}
    9991019\begin{tabular}{@{}l@{\hspace{50pt}}|l@{}}
     
    10031023while () { sout | "empty"; break; }
    10041024do { sout | "empty"; break; } while ();
    1005 for () { sout | "empty"; break; }                                                       §\C[3in]{sout | nl | nlOff;}§
     1025for () { sout | "empty"; break; }                                                       §\C{sout | nl | nlOff;}§
    10061026
    10071027for ( 0 ) { sout | "A"; } sout | "zero";                                        §\C{sout | nl;}§
     
    10451065for ( i; 5 : j; @ -~ -5 ~ 2 : k; 1.5 ~ @ ) { sout | i | j | k; } §\C{sout | nl;}§
    10461066for ( i; 5 : j; @ -~ -5 ~ 2 : k; 1.5 ~ @ ) { sout | i | j | k; } §\C{sout | nl;}§
    1047 for ( i; 5 : k; 1.5 ~ @ : j; @ -~ -5 ~ 2 ) { sout | i | j | k; } §\C{sout | nl;}\CRT§
     1067for ( i; 5 : k; 1.5 ~ @ : j; @ -~ -5 ~ 2 ) { sout | i | j | k; } §\C{sout | nl;}§
    10481068\end{cfa}
    10491069&
     
    11081128% for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1
    11091129
    1110 
    1111 \subsection{Loop Control}
    1112 
    1113 Looping a fixed number of times, possibly with a loop index, occurs frequently.
    1114 \CFA condenses simply looping to facilitate coding speed and safety~\see{examples in \VRef[Figure]{f:LoopControlExamples}}.
    1115 
    1116 The \Indexc{for}, \Indexc{while}, and \Indexc{do} loop-control allow an empty conditional, which implies a comparison value of ©1© (true).
    1117 \begin{cfa}
    1118 while ( ®/* empty */®  )                                §\C{// while ( true )}§
    1119 for ( ®/* empty */®  )                                  §\C{// for ( ; true; )}§
    1120 do ... while ( ®/* empty */®  )                 §\C{// do ... while ( true )}§
    1121 \end{cfa}
    1122 
    1123 The ©for© control has 4 new loop-control operators that are not overloadable:
     1130The ©for© control is extended with 4 new loop-control operators, which are not overloadable:
    11241131\begin{description}[itemsep=0pt,parsep=0pt]
    11251132\item
     
    11951202Similarly, the high value cannot be elided is an anonymous loop index (©1 ~ @©), as there is no index to stop the loop.
    11961203\item
    1197 ©:© means low another index.
     1204©:© means add another index.
    11981205\begin{cfa}
    11991206for ( i; 5 ®:® j; 2 ~ 12 ~ 3 )                  §\C{// for ( typeof(i) i = 1, j = 2; i < 5 \&\& j < 12; i += 1, j += 3 )}§
     
    12121219\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
    12131220
    1214 C \Indexc{continue} and \Indexc{break} statements, for altering control flow, are restricted to one level of nesting for a particular control structure.
     1221C \Indexc{continue} and \Indexc{break} statements are restricted to one level of nesting for a particular control structure.
    12151222This restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    12161223To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©break©!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}, as in Java.
     
    13021309Furthermore, the location of the label at the \emph{beginning} of the target control structure informs the reader (\Index{eye candy}) that complex control-flow is occurring in the body of the control structure.
    13031310With ©goto©, the label is at the end of the control structure, which fails to convey this important clue early enough to the reader.
    1304 Finally, using an explicit target for the transfer instead of an implicit target allows new constructs to be added or removed without affecting existing constructs.
     1311Finally, using an explicit target for the transfer, instead of an implicit target, allows new constructs to be added or removed without affecting existing constructs.
    13051312Otherwise, the implicit targets of the current ©continue© and ©break©, \ie the closest enclosing loop or ©switch©, change as certain constructs are added or removed.
    13061313
     
    13731380\begin{cfa}
    13741381Person p
    1375 ®p.®name; ®p.®address; ®p.®sex;                 §\C{// access containing fields}§
     1382®p.®name ...;  ®p.®address ...;  ®p.®sex ...; §\C{// access containing fields}§
    13761383\end{cfa}
    13771384which extends to multiple levels of qualification for nested aggregates and multiple aggregates.
    13781385\begin{cfa}
    13791386struct Ticket { ... } t;
    1380 ®p.name®.first; ®p.address®.street;             §\C{// access nested fields}§
    1381 ®t.®departure; ®t.®cost;                                §\C{// access multiple aggregate}§
     1387®p.name®.first ...;  ®p.address®.street ...; §\C{// access nested fields}§
     1388®t.®departure ...;  ®t.®cost ...;               §\C{// access multiple aggregate}§
    13821389\end{cfa}
    13831390Repeated aggregate qualification is tedious and makes code difficult to read.
     
    15581565
    15591566
    1560 \section{Non-local Exception}
     1567\subsection{Non-local Exception}
    15611568
    15621569\begin{cfa}
     
    23472354\subsection{Implicit String Conversions}
    23482355
    2349 The types ©char©, ©char *©, ©int©, ©double©, ©_Complex©, including signness and different sizes, implicitly convert to type ©string©.
    2350 \VRef[Figure]{f:ImplicitStringConversions} shows examples of implicit conversion between C strings, integral, floating-point and complex types to ©string©
    2351 The implicit conversions can be specified explicitly, as in:
    2352 \begin{cfa}
    2353 s = string( "abc" );            // converts char * to string
    2354 s = string( 5 );                        // converts int to string
    2355 s = string( 5.5 );                      // converts double to string
    2356 \end{cfa}
    2357 Conversions from ©string© to ©char *© are supported but with restrictions.
    2358 Explicit As well, when a string is converted to a ©char *©, the storage for the ©char *© is created by the conversion operation, which must be subsequently deleted:
    2359 \begin{cfa}
    2360 string x = "abc";
    2361 char *p = x;                            // convert from string to char *
    2362 ...
    2363 delete p;                                       // free storage created for p
    2364 \end{cfa}
     2356The types ©char©, ©char *©, ©int©, ©double©, ©_Complex©, including different signness and sizes, implicitly convert to type ©string©.
     2357\VRef[Figure]{f:ImplicitConversionsString} shows examples of implicit conversions between C strings, integral, floating-point and complex types to ©string©.
     2358A conversions can be explicitly specified:
     2359\begin{cfa}
     2360s = string( "abc" );                            §\C{// converts char * to string}§
     2361s = string( 5 );                                        §\C{// converts int to string}§
     2362s = string( 5.5 );                                      §\C{// converts double to string}§
     2363\end{cfa}
     2364All conversions from ©string© to ©char *©, attempt to be safe:
     2365either by requiring the maximum length of the ©char *© storage (©strncpy©) or allocating the ©char *© storage for the string characters (ownership), meaning the programmer must free the storage.
     2366As well, a string is always null terminates, implying a minimum size of 1 character.
     2367\begin{cquote}
     2368\begin{tabular}{@{}l@{\hspace{1.75in}}|@{\hspace{15pt}}l@{}}
     2369\begin{cfa}
     2370string s = "abcde";
     2371char cs[3];
     2372strncpy( cs, s, sizeof(cs) );           §\C{sout | cs;}§
     2373char * cp = s;                                          §\C{sout | cp;}§
     2374delete( cp );
     2375cp = s + ' ' + s;                                       §\C{sout | cp;}§
     2376delete( cp );
     2377\end{cfa}
     2378&
     2379\begin{cfa}
     2380
     2381
     2382ab
     2383abcde
     2384
     2385abcde abcde
     2386
     2387\end{cfa}
     2388\end{tabular}
     2389\end{cquote}
    23652390
    23662391\begin{figure}
     
    23702395        string s;
    23712396        // conversion of char and char * to string
    2372         s = 'x';                                                §\CD{sout | s;}§
    2373         s = "abc";                                              §\CD{sout | s;}§
     2397        s = 'x';                                                §\C{sout | s;}§
     2398        s = "abc";                                              §\C{sout | s;}§
    23742399        char cs[5] = "abc";
    2375         s = cs;                                                 §\CD{sout | s;}§
     2400        s = cs;                                                 §\C{sout | s;}§
    23762401        // conversion of integral, floating-point, and complex to string
    2377         s = 45hh;                                               §\CD{sout | s;}§
    2378         s = 45h;                                                §\CD{sout | s;}§
    2379         s = -(ssize_t)MAX - 1;                  §\CD{sout | s;}§
    2380         s = (size_t)MAX;                                §\CD{sout | s;}§
    2381         s = 5.5;                                                §\CD{sout | s;}§
    2382         s = 5.5L;                                               §\CD{sout | s;}§
    2383         s = 5.5+3.4i;                                   §\CD{sout | s;}§
    2384         s = 5.5L+3.4Li;                                 §\CD{sout | s;}§
    2385         // safe conversion from string to char *
    2386         strncpy( cs, s, sizeof(cs) );   §\CD{sout | cs;}§
    2387         char * cp = s;                                  §\CD{sout | cp; // ownership}§
    2388         delete( cp );
    2389         cp = s + ' ' + s;                               §\CD{sout | cp; // ownership}§
    2390         delete( cp );
     2402        s = 45hh;                                               §\C{sout | s;}§
     2403        s = 45h;                                                §\C{sout | s;}§
     2404        s = -(ssize_t)MAX - 1;                  §\C{sout | s;}§
     2405        s = (size_t)MAX;                                §\C{sout | s;}§
     2406        s = 5.5;                                                §\C{sout | s;}§
     2407        s = 5.5L;                                               §\C{sout | s;}§
     2408        s = 5.5+3.4i;                                   §\C{sout | s;}§
     2409        s = 5.5L+3.4Li;                                 §\C{sout | s;}§
    23912410\end{cfa}
    23922411&
     
    240824275.5+3.4i
    240924285.5+3.4i
    2410 
    2411 5.5+
    2412 5.5+3.4i
    2413 
    2414 5.5+3.4i 5.5+3.4i
    2415 
    24162429\end{cfa}
    24172430\end{tabular}
    2418 \caption{Implicit String Conversions}
    2419 \label{f:ImplicitStringConversions}
     2431\caption{Implicit Conversions to String}
     2432\label{f:ImplicitConversionsString}
    24202433\end{figure}
    24212434
    24222435
     2436\subsection{Size (length)}
     2437
     2438The ©size© operation returns the length of a string.
     2439\begin{cfa}
     2440i = size( "" );                                         §\C{// i is assigned 0}§
     2441i = size( "abc" );                                      §\C{// i is assigned 3}§
     2442i = size( peter );                                      §\C{// i is assigned 5}§
     2443\end{cfa}
     2444
     2445
    24232446\subsection{Comparison Operators}
    24242447
    2425 The binary relational and equality operators ©<©, ©<=©, ©>©, ©>=©, ©==©, ©!=© compare ©string© using lexicographical ordering, where longer strings are greater than shorter strings.
     2448The binary \Index{relational operator}s, ©<©, ©<=©, ©>©, ©>=©, and \Index{equality operator}s, ©==©, ©!=©, compare strings using lexicographical ordering, where longer strings are greater than shorter strings.
    24262449
    24272450
    24282451\subsection{Concatenation}
    24292452
    2430 The binary operator ©+© concatenates two strings.
    2431 \begin{cfa}
    2432 s = peter + digit;                                      §\C{// s is assigned "PETER0123456789"}§
    2433 s += peter;                                                     §\C{// s is assigned "PETER0123456789PETER"}§
    2434 \end{cfa}
    2435 There is also an assignment form ©+=©.
     2453The binary operators \Indexc{+} and \Indexc{+=} concatenate two strings, creating the sum of the strings.
     2454\begin{cfa}
     2455s = peter + ' ' + digit;                        §\C{// s is assigned "PETER 0123456789"}§
     2456s += peter;                                                     §\C{// s is assigned "PETER 0123456789PETER"}§
     2457\end{cfa}
    24362458
    24372459
    24382460\subsection{Repetition}
    24392461
    2440 The binary operator \Indexc{*} returns a string that is the string repeated ©n© times.
    2441 If ©n = 0©, a zero length string, ©""© is returned.
    2442 \begin{cfa}
    2443 s = (peter + ' ') * 3;                          §\C{// s is assigned "PETER PETER PETER"}§
    2444 \end{cfa}
    2445 There is also an assignment form ©*=©.
    2446 
    2447 
    2448 \subsection{Length}
    2449 
    2450 The ©length© operation
    2451 \begin{cfa}
    2452 int length()
    2453 \end{cfa}
    2454 returns the length of a string variable.
    2455 \begin{cfa}
    2456 i = peter.length();                     §\C{// i is assigned the value 5}§
     2462The binary operators \Indexc{*} and \Indexc{*=} repeat a string $N$ times.
     2463If $N = 0$, a zero length string, ©""© is returned.
     2464\begin{cfa}
     2465s = 'x' * 3;                            §\C{// s is assigned "PETER PETER PETER "}§
     2466s = (peter + ' ') * 3;                          §\C{// s is assigned "PETER PETER PETER "}§
    24572467\end{cfa}
    24582468
    24592469
    24602470\subsection{Substring}
    2461 The substring operation:
    2462 \begin{cfa}
    2463 string operator () (int start, int lnth);
    2464 \end{cfa}
    2465 performs a substring operation that returns the string starting at a specified position (©start©) in the current string, and having the specified length (©lnth©).
     2471The substring operation returns a subset of the string starting at a position in the string and traversing a length.
     2472\begin{cfa}
     2473s = peter( 2, 3 );                                      §\C{// s is assigned "ETE"}§
     2474s = peter( 4, -3 );                                     §\C{// s is assigned "ETE", length is opposite direction}§
     2475s = peter( 2, 8 );                                      §\C{// s is assigned "ETER", length is clipped to 4}§
     2476s = peter( 0, -1 );                                     §\C{// s is assigned "", beyond string so clipped to null}§
     2477s = peter(-1, -1 );                                     §\C{// s is assigned "R", start and length are negative}§
     2478\end{cfa}
    24662479A negative starting position is a specification from the right end of the string.
    24672480A negative length means that characters are selected in the opposite (right to left) direction from the starting position.
    24682481If the substring request extends beyond the beginning or end of the string, it is clipped (shortened) to the bounds of the string.
    24692482If the substring request is completely outside of the original string, a null string located at the end of the original string is returned.
    2470 \begin{cfa}
    2471 s = peter( 2, 3 );                      §\C{// s is assigned "ETE"}§
    2472 s = peter( 4, -3 );                     §\C{// s is assigned "ETE", length is opposite direction}§
    2473 s = peter( 2, 8 );                      §\C{// s is assigned "ETER", length is clipped to 4}§
    2474 s = peter( 0, -1 );                     §\C{// s is assigned "", beyond string so clipped to null}§
    2475 s = peter(-1, -1 );                     §\C{// s is assigned "R", start and length are negative}§
    2476 \end{cfa}
    24772483The substring operation can also appear on the left hand side of the assignment operator.
    24782484The substring is replaced by the value on the right hand side of the assignment.
    24792485The length of the right-hand-side value may be shorter, the same length, or longer than the length of the substring that is selected on the left hand side of the assignment.
    2480 \begin{cfa}[mathescape=false]
    2481 digit( 3, 3 ) = "";             §\C{// digit is assigned "0156789"}§
    2482 digit( 4, 3 ) = "xyz";          §\C{// digit is assigned "015xyz9"}§
    2483 digit( 7, 0 ) = "***";          §\C{// digit is assigned "015xyz***9"}§
    2484 digit(-4, 3 ) = "$$$";          §\C{// digit is assigned "015xyz\$\$\$9"}§
     2486\begin{cfa}
     2487digit( 3, 3 ) = "";                             §\C{// digit is assigned "0156789"}§
     2488digit( 4, 3 ) = "xyz";                          §\C{// digit is assigned "015xyz9"}§
     2489digit( 7, 0 ) = "***";                          §\C{// digit is assigned "015xyz***9"}§
     2490digit(-4, 3 ) = "$$$";                          §\C{// digit is assigned "015xyz\$\$\$9"}§
    24852491\end{cfa}
    24862492A substring is treated as a pointer into the base (substringed) string rather than creating a copy of the subtext.
     
    25012507// e is a substring result passed by value
    25022508void test(string &x, string &a, string &b, string &c, string &d, string e) {
    2503                                                         §\C{//   x                                a               b               c               d               e}§
    2504         a( 1, 2 ) = "aaa";              §\C{// aaaxxxxxxxxxxx   aaax    axx             xxxxx   xxxxx   xxxxx}§
    2505         b( 2, 12 ) = "bbb";             §\C{// aaabbbxxxxxxxxx  aaab    abbb    bbxxx   xxxxx   xxxxx}§
    2506         c( 4, 5 ) = "ccc";              §\C{// aaabbbxcccxxxxxx aaab    abbb    bbxccc  ccxxx   xxxxx}§
    2507         c = "yyy";                              §\C{// aaabyyyxxxxxx    aaab    abyy    yyy             xxxxx   xxxxx}§
    2508         d( 1, 3 ) = "ddd";              §\C{// aaabyyyxdddxx    aaab    abyy    yyy             dddxx   xxxxx}§
    2509         e( 1, 3 ) = "eee";              §\C{// aaabyyyxdddxx    aaab    abyy    yyy             dddxx   eeexx}§
    2510         x = e;                                  §\C{// eeexx                    eeex    exx             x                               eeexx}§
     2509                                                                        §\C{//   x                                a               b               c               d               e}§
     2510        a( 1, 2 ) = "aaa";                              §\C{// aaaxxxxxxxxxxx   aaax    axx             xxxxx   xxxxx   xxxxx}§
     2511        b( 2, 12 ) = "bbb";                             §\C{// aaabbbxxxxxxxxx  aaab    abbb    bbxxx   xxxxx   xxxxx}§
     2512        c( 4, 5 ) = "ccc";                              §\C{// aaabbbxcccxxxxxx aaab    abbb    bbxccc  ccxxx   xxxxx}§
     2513        c = "yyy";                                              §\C{// aaabyyyxxxxxx    aaab    abyy    yyy             xxxxx   xxxxx}§
     2514        d( 1, 3 ) = "ddd";                              §\C{// aaabyyyxdddxx    aaab    abyy    yyy             dddxx   xxxxx}§
     2515        e( 1, 3 ) = "eee";                              §\C{// aaabyyyxdddxx    aaab    abyy    yyy             dddxx   eeexx}§
     2516        x = e;                                                  §\C{// eeexx                    eeex    exx             x                               eeexx}§
    25112517}
    25122518\end{cfa}
     
    25182524For example:
    25192525\begin{cfa}
    2520 s = peter( 2 );                         §\C{// s is assigned "ETER"}§
    2521 peter( 2 ) = "IPER";            §\C{// peter is assigned "PIPER"}§
     2526s = peter( 2 );                                         §\C{// s is assigned "ETER"}§
     2527peter( 2 ) = "IPER";                            §\C{// peter is assigned "PIPER"}§
    25222528\end{cfa}
    25232529It is also possible to substring using a string as the index for selecting the substring portion of the string.
     
    25272533For example:
    25282534\begin{cfa}[mathescape=false]
    2529 digit( "xyz$$$" ) = "678";      §\C{// digit is assigned "0156789"}§
    2530 digit( "234") = "***";          §\C{// digit is assigned "0156789***"}§
    2531 \end{cfa}
    2532 %$
     2535digit( "xyz$$$" ) = "678";                      §\C{// digit is assigned "0156789"}§
     2536digit( "234") = "***";                          §\C{// digit is assigned "0156789***"}§
     2537\end{cfa}
    25332538
    25342539
     
    25702575A negative starting position is a specification from the right end of the string.
    25712576\begin{cfa}
    2572 i = peter.include( digitmask ); §\C{// i is assigned 1}§
    2573 i = peter.include( alphamask ); §\C{// i is assigned 6}§
     2577i = peter.include( digitmask );         §\C{// i is assigned 1}§
     2578i = peter.include( alphamask );         §\C{// i is assigned 6}§
    25742579\end{cfa}
    25752580
     
    26222627\begin{cfa}
    26232628// remove leading blanks
    2624 s = string( "   ABC" ).trim( " " );                     §\C{// s is assigned "ABC",}§
     2629s = string( "   ABC" ).trim( " " );     §\C{// s is assigned "ABC",}§
    26252630// remove trailing blanks
    2626 s = string( "ABC   " ).trim( " ", last );       §\C{// s is assigned "ABC",}§
     2631s = string( "ABC   " ).trim( " ", last ); §\C{// s is assigned "ABC",}§
    26272632\end{cfa}
    26282633
     
    26512656returns a string in which all occurrences of the ©from© string in the current string have been replaced by the ©to© string.
    26522657\begin{cfa}
    2653 s = peter.replace( "E", "XX" ); §\C{// s is assigned "PXXTXXR"}§
     2658s = peter.replace( "E", "XX" );         §\C{// s is assigned "PXXTXXR"}§
    26542659\end{cfa}
    26552660The replacement is done left-to-right.
    26562661When an instance of the ©from© string is found and changed to the ©to© string, it is NOT examined again for further replacement.
    26572662
    2658 
    2659 \section{Returning N+1 on Failure}
     2663\subsection{Returning N+1 on Failure}
    26602664
    26612665Any of the string search routines can fail at some point during the search.
     
    26872691
    26882692
     2693\subsection{C Compatibility}
     2694
     2695To ease conversion from C to \CFA, there are companion ©string© routines for C strings.
     2696\VRef[Table]{t:CompanionStringRoutines} shows the C routines on the left that also work with ©string© and the rough equivalent ©string© opeation of the right.
     2697Hence, it is possible to directly convert a block of C string operations into @string@ just by changing the
     2698
     2699\begin{table}
     2700\begin{cquote}
     2701\begin{tabular}{@{}l|l@{}}
     2702\multicolumn{1}{c|}{©char []©}  & \multicolumn{1}{c}{©string©}  \\
     2703\hline
     2704©strcpy©, ©strncpy©             & ©=©                                                                   \\
     2705©strcat©, ©strncat©             & ©+©                                                                   \\
     2706©strcmp©, ©strncmp©             & ©==©, ©!=©, ©<©, ©<=©, ©>©, ©>=©              \\
     2707©strlen©                                & ©size©                                                                \\
     2708©[]©                                    & ©[]©                                                                  \\
     2709©strstr©                                & ©find©                                                                \\
     2710©strcspn©                               & ©find_first_of©, ©find_last_of©               \\
     2711©strspc©                                & ©find_fist_not_of©, ©find_last_not_of©
     2712\end{tabular}
     2713\end{cquote}
     2714\caption{Companion Routines for \CFA \lstinline{string} to C Strings}
     2715\label{t:CompanionStringRoutines}
     2716\end{table}
     2717
     2718For example, this block of C code can be converted to \CFA by simply changing the type of variable ©s© from ©char []© to ©string©.
     2719\begin{cfa}
     2720        char s[32];
     2721        //string s;
     2722        strcpy( s, "abc" );                             PRINT( %s, s );
     2723        strncpy( s, "abcdef", 3 );              PRINT( %s, s );
     2724        strcat( s, "xyz" );                             PRINT( %s, s );
     2725        strncat( s, "uvwxyz", 3 );              PRINT( %s, s );
     2726        PRINT( %zd, strlen( s ) );
     2727        PRINT( %c, s[3] );
     2728        PRINT( %s, strstr( s, "yzu" ) ) ;
     2729        PRINT( %s, strstr( s, 'y' ) ) ;
     2730\end{cfa}
     2731However, the conversion fails with I/O because ©printf© cannot print a ©string© using format code ©%s© because \CFA strings are not null terminated.
     2732
     2733
    26892734\subsection{Input/Output Operators}
    26902735
     
    27072752Hence, enums may be overloaded with variable, enum, and function names.
    27082753\begin{cfa}
    2709 int Foo;                        §\C{// type/variable separate namespaces}§
     2754int Foo;                                                        §\C{// type/variable separate namespaces}§
    27102755enum Foo { Bar };
    2711 enum Goo { Bar };       §\C[1.75in]{// overload Foo.Bar}§
    2712 double Bar;                     §\C{// overload Foo.Bar, Goo.Bar}\CRT§
     2756enum Goo { Bar };                                       §\C{// overload Foo.Bar}§
     2757double Bar;                                                     §\C{// overload Foo.Bar, Goo.Bar}§
    27132758\end{cfa}
    27142759An anonymous enumeration injects enums with specific values into a scope.
     
    27832828The following examples illustrate the difference between the enumeration type and the type of its enums.
    27842829\begin{cfa}
    2785 Math m = PI;    §\C[1.5in]{// allowed}§
    2786 double d = PI;  §\C{// allowed, conversion to base type}§
    2787 m = E;                  §\C{// allowed}§
    2788 m = Alph;               §\C{// {\color{red}disallowed}}§
    2789 m = 3.141597;   §\C{// {\color{red}disallowed}}§
    2790 d = m;                  §\C{// allowed}§
    2791 d = Alph;               §\C{// {\color{red}disallowed}}§
    2792 Letter l = A;   §\C{// allowed}§
    2793 Greek g = Alph; §\C{// allowed}§
    2794 l = Alph;               §\C{// allowed, conversion to base type}§
    2795 g = A;                  §\C{// {\color{red}disallowed}}\CRT§
     2830Math m = PI;                                            §\C{// allowed}§
     2831double d = PI;                                          §\C{// allowed, conversion to base type}§
     2832m = E;                                                          §\C{// allowed}§
     2833m = Alph;                                                       §\C{// {\color{red}disallowed}}§
     2834m = 3.141597;                                           §\C{// {\color{red}disallowed}}§
     2835d = m;                                                          §\C{// allowed}§
     2836d = Alph;                                                       §\C{// {\color{red}disallowed}}§
     2837Letter l = A;                                           §\C{// allowed}§
     2838Greek g = Alph;                                         §\C{// allowed}§
     2839l = Alph;                                                       §\C{// allowed, conversion to base type}§
     2840g = A;                                                          §\C{// {\color{red}disallowed}}§
    27962841\end{cfa}
    27972842
     
    33623407For example, consider C's \Indexc{div} function, which returns the quotient and remainder for a division of an integer value.
    33633408\begin{cfa}
    3364 typedef struct { int quot, rem; } div_t;        §\C[7cm]{// from include stdlib.h}§
     3409typedef struct { int quot, rem; } div_t; §\C{// from include stdlib.h}§
    33653410div_t div( int num, int den );
    3366 div_t qr = div( 13, 5 ); §\C{// return quotient/remainder aggregate}§
     3411div_t qr = div( 13, 5 );                                §\C{// return quotient/remainder aggregate}§
    33673412printf( "%d %d\n", qr.quot, qr.rem ); §\C{// print quotient/remainder}§
    33683413\end{cfa}
     
    33753420For example, consider C's \Indexc{modf} function, which returns the integral and fractional part of a floating value.
    33763421\begin{cfa}
    3377 double modf( double x, double * i ); §\C{// from include math.h}§
     3422double modf( double x, double * i );    §\C{// from include math.h}§
    33783423double intp, frac = modf( 13.5, &intp ); §\C{// return integral and fractional components}§
    33793424printf( "%g %g\n", intp, frac ); §\C{// print integral/fractional components}§
     
    34043449When a function call is passed as an argument to another call, the best match of actual arguments to formal parameters is evaluated given all possible expression interpretations in the current scope.
    34053450\begin{cfa}
    3406 void g( int, int ); §\C{// 1}§
    3407 void g( double, double ); §\C{// 2}§
    3408 g( div( 13, 5 ) ); §\C{// select 1}§
    3409 g( modf( 13.5 ) ); §\C{// select 2}§
     3451void g( int, int );                                             §\C{// 1}§
     3452void g( double, double );                               §\C{// 2}§
     3453g( div( 13, 5 ) );                                              §\C{// select 1}§
     3454g( modf( 13.5 ) );                                              §\C{// select 2}§
    34103455\end{cfa}
    34113456In this case, there are two overloaded ©g© routines.
     
    34163461The previous examples can be rewritten passing the multiple returned-values directly to the ©printf© function call.
    34173462\begin{cfa}
    3418 [ int, int ] div( int x, int y ); §\C{// from include stdlib}§
     3463[ int, int ] div( int x, int y );               §\C{// from include stdlib}§
    34193464printf( "%d %d\n", div( 13, 5 ) ); §\C{// print quotient/remainder}§
    34203465
    3421 [ double, double ] modf( double x ); §\C{// from include math}§
     3466[ double, double ] modf( double x );    §\C{// from include math}§
    34223467printf( "%g %g\n", modf( 13.5 ) ); §\C{// print integral/fractional components}§
    34233468\end{cfa}
     
    34303475\begin{cfa}
    34313476int quot, rem;
    3432 [ quot, rem ] = div( 13, 5 ); §\C{// assign multiple variables}§
    3433 printf( "%d %d\n", quot, rem ); §\C{// print quotient/remainder}\CRT§
     3477[ quot, rem ] = div( 13, 5 );                   §\C{// assign multiple variables}§
     3478printf( "%d %d\n", quot, rem );                 §\C{// print quotient/remainder}§
    34343479\end{cfa}
    34353480Here, the multiple return-values are matched in much the same way as passing multiple return-values to multiple parameters in a call.
     
    38483893The general syntax of a lexical list is:
    38493894\begin{cfa}
    3850 [ $\emph{exprlist}$ ]
    3851 \end{cfa}
    3852 where ©$\emph{exprlist}$© is a list of one or more expressions separated by commas.
     3895[ §\emph{exprlist}§ ]
     3896\end{cfa}
     3897where \LstBasicStyle{\emph{exprlist}} is a list of one or more expressions separated by commas.
    38533898The brackets, ©[]©, allow differentiating between lexical lists and expressions containing the C comma operator.
    38543899The following are examples of lexical lists:
     
    38563901[ x, y, z ]
    38573902[ 2 ]
    3858 [ v+w, x*y, 3.14159, f() ]
     3903[ v + w, x * y, 3.14159, f() ]
    38593904\end{cfa}
    38603905Tuples are permitted to contain sub-tuples (\ie nesting), such as ©[ [ 14, 21 ], 9 ]©, which is a 2-element tuple whose first element is itself a tuple.
     
    38683913The general syntax of a tuple type is:
    38693914\begin{cfa}
    3870 [ $\emph{typelist}$ ]
    3871 \end{cfa}
    3872 where ©$\emph{typelist}$© is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.
     3915[ §\emph{typelist}§ ]
     3916\end{cfa}
     3917where \LstBasicStyle{\emph{typelist}} is a list of one or more legal \CFA or C type specifications separated by commas, which may include other tuple type specifications.
    38733918Examples of tuple types include:
    38743919\begin{cfa}
    38753920[ unsigned int, char ]
    38763921[ double, double, double ]
    3877 [ * int, int * ] §\C{// mix of CFA and ANSI}§
     3922[ * int, int * ]                                                §\C{// mix of CFA and ANSI}§
    38783923[ * [ 5 ] int, * * char, * [ [ int, int ] ] (int, int) ]
    38793924\end{cfa}
     
    38823927Examples of declarations using tuple types are:
    38833928\begin{cfa}
    3884 [ int, int ] x; §\C{// 2 element tuple, each element of type int}§
    3885 * [ char, char ] y; §\C{// pointer to a 2 element tuple}§
     3929[ int, int ] x;                                                 §\C{// 2 element tuple, each element of type int}§
     3930* [ char, char ] y;                                             §\C{// pointer to a 2 element tuple}§
    38863931[ [ int, int ] ] z ([ int, int ]);
    38873932\end{cfa}
     
    39003945[ int, int ] w1;
    39013946[ int, int, int ] w2;
    3902 [ void ] f (int, int, int); §\C{// three input parameters of type int}§
    3903 [ void ] g ([ int, int, int ]); §\C{3 element tuple as input}§
     3947[ void ] f (int, int, int);                             §\C{// three input parameters of type int}§
     3948[ void ] g ([ int, int, int ]);                 §\C{// 3 element tuple as input}§
    39043949f( [ 1, 2, 3 ] );
    39053950f( w1, 3 );
     
    39824027[ int, int, int, int ] w = [ 1, 2, 3, 4 ];
    39834028int x = 5;
    3984 [ x, w ] = [ w, x ]; §\C{// all four tuple coercions}§
     4029[ x, w ] = [ w, x ];                                    §\C{// all four tuple coercions}§
    39854030\end{cfa}
    39864031Starting on the right-hand tuple in the last assignment statement, w is opened, producing a tuple of four values;
     
    40004045Mass assignment has the following form:
    40014046\begin{cfa}
    4002 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = $\emph{expr}$;
     4047[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = §\emph{expr}§;
    40034048\end{cfa}
    40044049\index{lvalue}
    4005 The left-hand side is a tuple of \emph{lvalues}, which is a list of expressions each yielding an address, \ie any data object that can appear on the left-hand side of a conventional assignment statement.
    4006 ©$\emph{expr}$© is any standard arithmetic expression.
     4050The left-hand side is a tuple of \LstBasicStyle{\emph{lvalues}}, which is a list of expressions each yielding an address, \ie any data object that can appear on the left-hand side of a conventional assignment statement.
     4051\LstBasicStyle{\emph{expr}} is any standard arithmetic expression.
    40074052Clearly, the types of the entities being assigned must be type compatible with the value of the expression.
    40084053
     
    40414086Multiple assignment has the following form:
    40424087\begin{cfa}
    4043 [ $\emph{lvalue}$, ... , $\emph{lvalue}$ ] = [ $\emph{expr}$, ... , $\emph{expr}$ ];
     4088[ §\emph{lvalue}§, ... , §\emph{lvalue}§ ] = [ §\emph{expr}§, ... , §\emph{expr}§ ];
    40444089\end{cfa}
    40454090\index{lvalue}
     
    40724117both these examples produce indeterminate results:
    40734118\begin{cfa}
    4074 f( x++, x++ ); §\C{// C routine call with side effects in arguments}§
    4075 [ v1, v2 ] = [ x++, x++ ]; §\C{// side effects in right-hand side of multiple assignment}§
     4119f( x++, x++ );                                                  §\C{// C routine call with side effects in arguments}§
     4120[ v1, v2 ] = [ x++, x++ ];                              §\C{// side effects in right-hand side of multiple assignment}§
    40764121\end{cfa}
    40774122
     
    40834128Cascade assignment has the following form:
    40844129\begin{cfa}
    4085 $\emph{tuple}$ = $\emph{tuple}$ = ... = $\emph{tuple}$;
     4130§\emph{tuple}§ = §\emph{tuple}§ = ... = §\emph{tuple}§;
    40864131\end{cfa}
    40874132and it has the same parallel semantics as for mass and multiple assignment.
     
    41034148The goal of \CFA stream input/output (I/O) is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
    41044149Stream I/O can be implicitly or explicitly formatted.
    4105 Implicit formatting means \CFA selects the output or input format for values that matches the variable's type.
    4106 Explicit formatting means additional information is specified to augment how an output or input of value is interpreted.
     4150Implicit formatting means \CFA selects an I/O format for values that matches a variable's type.
     4151Explicit formatting means additional I/O information is specified to control how a value is interpreted.
     4152
    41074153\CFA formatting incorporates ideas from C ©printf©, \CC ©stream© manipulators, and Python implicit spacing and newline.
    41084154Specifically:
     
    41124158\CFA/\CC format manipulators are named, making them easier to read and remember.
    41134159\item
    4114 ©printf©/Python separates format codes from associated variables, making it difficult to match codes with variables.
     4160©printf©/Python separate format codes from associated variables, making it difficult to match codes with variables.
    41154161\CFA/\CC co-locate codes with associated variables, where \CFA has the tighter binding.
    41164162\item
    4117 Format manipulators in \CFA have local effect, whereas \CC have global effect, except ©setw©.
    4118 Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
     4163Format manipulators in ©printf©/Python/\CFA have local effect, whereas \CC have global effect, except ©setw©.
     4164Hence, it is common \CC programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
    41194165Without this programming style, errors occur when moving prints, as manipulator effects incorrectly flow into the new location.
    41204166Furthermore, to guarantee no side-effects, manipulator values must be saved and restored across function calls.
     4167\CC programers never do any of this.
    41214168\item
    41224169\CFA has more sophisticated implicit value spacing than Python, plus implicit newline at the end of a print.
    41234170\end{itemize}
    41244171
    4125 The standard polymorphic I/Os stream are ©stdin©/©sin© (input), ©stdout©/©sout© and ©stderr©/©serr© (output) (like C++ ©cin©/©cout©/©cerr©).
    4126 Polymorphic streams ©exit© and ©abort© provide implicit program termination without and with generating a stack trace and core file.
    4127 Stream ©exit© implicitly returns ©EXIT_FAILURE© to the shell.
    4128 \begin{cfa}
    4129 ®exit®   | "x (" | x | ") negative value.";   // terminate and return EXIT_FAILURE to shell
    4130 ®abort® | "x (" | x | ") negative value.";   // terminate and generate stack trace and core file
    4131 \end{cfa}
    4132 Note, \CFA stream variables ©stdin©, ©stdout©, ©stderr©, ©exit©, and ©abort© overload C variables ©stdin©, ©stdout©, ©stderr©, and functions ©exit© and ©abort©, respectively.
     4172
     4173\subsection{Basic I/O}
     4174
     4175The standard polymorphic I/O streams are ©stdin©/©sin© (input), ©stdout©/©sout©, and ©stderr©/©serr© (output) (like C++ ©cin©/©cout©/©cerr©).
     4176The standard I/O operator is the bit-wise (or) operator, ©'|'©, which is used to cascade multiple I/O operations.
    41334177The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
    4134 
    4135 
    4136 \subsection{Basic I/O}
    41374178
    41384179For implicit formatted output, the common case is printing a series of variables separated by whitespace.
     
    417742181®, ®2®, ®3 4®, ®5®, ®6
    41784219\end{cfa}
    4179 Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     4220The bit-wise ©|© operator is used for I/O, rather \CC shift-operators, ©<<© and ©>>©, as it is the lowest-priority \emph{overloadable} operator, other than assignment.
     4221(Operators ©||© and ©&&© are not overloadable in \CFA.)
    41804222Therefore, fewer output expressions require parenthesis.
    41814223\begin{cquote}
     
    42004242\end{cquote}
    42014243There is a weak similarity between the \CFA logical-or operator and the \Index{Shell pipe-operator} for moving data, where data flows in the correct direction for input but the opposite direction for output.
    4202 Input and output use a uniform operator, ©|©, rather than \CC's ©<<© and ©>>© input/output operators, which prevents this common error in \CC:
     4244Input and output use a uniform operator, ©|©, rather than \CC's ©<<© and ©>>© input/output operators to prevent this common error in \CC:
    42034245\begin{C++}
    42044246cin << i; // why is this generating a lot of error messages?
    42054247\end{C++}
     4248
     4249Streams ©exit© and ©abort© provide output with immediate program termination without and with generating a stack trace and core file.
     4250Stream ©exit© implicitly returns ©EXIT_FAILURE© to the shell.
     4251\begin{cfa}
     4252®exit®   | "x (" | x | ") negative value.";     §\C{// print, terminate, and return EXIT\_FAILURE to shell}§
     4253®abort® | "x (" | x | ") negative value.";      §\C{// print, terminate, and generate stack trace and core file}§
     4254\end{cfa}
     4255Note, \CFA stream variables ©stdin©, ©stdout©, ©stderr©, ©exit©, and ©abort© overload C variables ©stdin©, ©stdout©, ©stderr©, and functions ©exit© and ©abort©, respectively.
    42064256
    42074257For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable.
     
    42464296\end{tabular}
    42474297\end{cquote}
    4248 
    4249 \VRef[Figure]{f:CFACommand-LineProcessing} shows idiomatic \CFA command-line processing and copying an input file to an output file.
     4298The format of numeric input values in the same as C constants without a trailing type suffix, as the input value-type is denoted by the input variable.
     4299For ©bool© type, the constants are ©true© and ©false©.
     4300For integral types, any number of digits, optionally preceded by a sign (©+© or ©-©), where a
     4301\begin{itemize}
     4302\item
     4303©1©-©9© prefix introduces a decimal value (©0©-©9©),
     4304\item
     4305©0© prefix introduces an octal value (©0©-©7©), and
     4306\item
     4307©0x© or ©0X© prefix introduces a hexadecimal value (©0©-©f©) with lower or upper case letters.
     4308\end{itemize}
     4309For floating-point types, any number of decimal digits, optionally preceded by a sign (©+© or ©-©), optionally containing a decimal point, and optionally followed by an exponent, ©e© or ©E©, with signed (optional) decimal digits.
     4310Floating-point values can also be written in hexadecimal format preceded by ©0x© or ©0X© with hexadecimal digits and exponent denoted by ©p© or ©P©.
     4311In all cases, all whitespace characters are skipped until an appropriate value is found.
     4312\Textbf{If an appropriate value is not found, the exception ©missing_data© is raised.}
     4313
     4314For the C-string type, there are two input forms: any number of \Textbf{non-whitespace} characters or a quoted sequence containing any characters except the closing quote, \ie there is no escape character supported in the string..
     4315In both cases, the string is null terminated ©'\0'©.
     4316For the quoted string, the start and end quote characters can be any character and do not have to match \see{\ref{XXX}}.
     4317
     4318\VRef[Figure]{f:IOStreamFunctions} shows the I/O stream operations for interacting with files other than ©cin©, ©cout©, and ©cerr©.
     4319\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
     4320\item
     4321\Indexc{fail} tests the stream error-indicator, returning nonzero if it is set.
     4322\item
     4323\Indexc{clear} resets the stream error-indicator.
     4324\item
     4325\Indexc{flush} (©ofstream© only) causes any unwritten data for a stream to be written to the file.
     4326\item
     4327\Indexc{eof} (©ifstream© only) tests the end-of-file indicator for the stream pointed to by stream.
     4328Returns true if the end-of-file indicator is set, otherwise false.
     4329\item
     4330\Indexc{open} binds the file with ©name© to a stream accessed with ©mode© (see ©fopen©).
     4331\item
     4332\Indexc{close} flushes the stream and closes the file.
     4333\item
     4334\Indexc{write} (©ofstream© only) writes ©size© bytes to the stream.
     4335The bytes are written lazily when an internal buffer fills.
     4336Eager buffer writes are done with ©flush©
     4337\item
     4338\Indexc{read} (©ifstream© only) reads ©size© bytes from the stream.
     4339\item
     4340\Indexc{ungetc} (©ifstream© only) pushes the character back to the input stream.
     4341Pushed-back characters returned by subsequent reads in the reverse order of pushing.
     4342\end{itemize}
     4343The constructor functions:
     4344\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
     4345\item
     4346create an unbound stream, which is subsequently bound to a file with ©open©.
     4347\item
     4348create a bound stream to the associated file with given ©mode©.
     4349\end{itemize}
     4350The destructor closes the stream.
     4351
     4352\begin{figure}
     4353\begin{cfa}
     4354// *********************************** ofstream ***********************************
     4355bool fail( ofstream & );§\indexc{fail}\index{ofstream@©ofstream©!©fail©}§
     4356void clear( ofstream & );§\indexc{clear}\index{ofstream@©ofstream©!©clear©}§
     4357int flush( ofstream & );§\indexc{flush}\index{ofstream@©ofstream©!©flush©}§
     4358void open( ofstream &, const char name[], const char mode[] = "w" );§\indexc{open}\index{ofstream@©ofstream©!©open©}§
     4359void close( ofstream & );§\indexc{close}\index{ofstream@©ofstream©!©close©}§
     4360ofstream & write( ofstream &, const char data[], size_t size );§\indexc{write}\index{ofstream@©ofstream©!©write©}§
     4361void ?{}( ofstream & );§\index{ofstream@©ofstream©!©?{}©}§
     4362void ?{}( ofstream &, const char name[], const char mode[] = "w" );
     4363void ^?{}( ofstream & );§\index{ofstream@©ofstream©!©^?{}©}§
     4364
     4365// *********************************** ifstream ***********************************
     4366bool fail( ifstream & is );§\indexc{fail}\index{ifstream@©ifstream©!©fail©}§
     4367void clear( ifstream & );§\indexc{clear}\index{ifstream@©ifstream©!©clear©}§
     4368bool eof( ifstream & is );§\indexc{eof}\index{ifstream@©ifstream©!©eof©}§
     4369void open( ifstream & is, const char name[], const char mode[] = "r" );§\indexc{open}\index{ifstream@©ifstream©!©open©}§
     4370void close( ifstream & is );§\indexc{close}\index{ifstream@©ifstream©!©close©}§
     4371ifstream & read( ifstream & is, char data[], size_t size );§\indexc{read}\index{ifstream@©ifstream©!©read©}§
     4372ifstream & ungetc( ifstream & is, char c );§\indexc{unget}\index{ifstream@©ifstream©!©unget©}§
     4373void ?{}( ifstream & is );§\index{ifstream@©ifstream©!©?{}©}§
     4374void ?{}( ifstream & is, const char name[], const char mode[] = "r" );
     4375void ^?{}( ifstream & is );§\index{ifstream@©ifstream©!©^?{}©}§
     4376\end{cfa}
     4377\caption{I/O Stream Functions}
     4378\label{f:IOStreamFunctions}
     4379\end{figure}
     4380
     4381\VRef[Figure]{f:CFACommand-LineProcessing} demonstrates the file operations by showing the idiomatic \CFA command-line processing and copying an input file to an output file.
    42504382Note, a stream variable may be copied because it is a reference to an underlying stream data-structures.
    4251 All I/O errors are handles as exceptions, but end-of-file is not an exception as C programmers are use to explicitly checking for it.
     4383\Textbf{All I/O errors are handled as exceptions}, but end-of-file is not an exception as C programmers are use to explicitly checking for it.
    42524384
    42534385\begin{figure}
     
    42614393        try {
    42624394                choose ( argc ) {
    4263                   case 2, 3:
     4395                  case 3, 2:
    42644396                        ®open®( in, argv[1] );                  §\C{// open input file first as output creates file}§
    42654397                        if ( argc == 3 ) ®open®( out, argv[2] ); §\C{// do not create output unless input opens}§
     
    42904422\end{figure}
    42914423
    4292 \VRef[Figure]{f:StreamFunctions} shows the stream operations.
    4293 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    4294 \item
    4295 \Indexc{fail} tests the stream error-indicator, returning nonzero if it is set.
    4296 \item
    4297 \Indexc{clear} resets the stream error-indicator.
    4298 \item
    4299 \Indexc{flush} (©ofstream© only) causes any unwritten data for a stream to be written to the file.
    4300 \item
    4301 \Indexc{eof} (©ifstream© only) tests the end-of-file indicator for the stream pointed to by stream.
    4302 Returns true if the end-of-file indicator is set, otherwise false.
    4303 \item
    4304 \Indexc{open} binds the file with ©name© to a stream accessed with ©mode© (see ©fopen©).
    4305 \item
    4306 \Indexc{close} flushes the stream and closes the file.
    4307 \item
    4308 \Indexc{write} (©ofstream© only) writes ©size© bytes to the stream.
    4309 The bytes are written lazily when an internal buffer fills.
    4310 Eager buffer writes are done with ©flush©
    4311 \item
    4312 \Indexc{read} (©ifstream© only) reads ©size© bytes from the stream.
    4313 \item
    4314 \Indexc{ungetc} (©ifstream© only) pushes the character back to the input stream.
    4315 Pushed-back characters returned by subsequent reads in the reverse order of pushing.
    4316 \end{itemize}
    4317 The constructor functions:
    4318 \begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
    4319 \item
    4320 create an unbound stream, which is subsequently bound to a file with ©open©.
    4321 \item
    4322 create a bound stream to the associated file with given ©mode©.
    4323 \end{itemize}
    4324 The destructor closes the stream.
    4325 
    4326 \begin{figure}
    4327 \begin{cfa}
    4328 // *********************************** ofstream ***********************************
    4329 
    4330 bool fail( ofstream & );§\indexc{fail}\index{ofstream@©ofstream©!©fail©}§
    4331 void clear( ofstream & );§\indexc{clear}\index{ofstream@©ofstream©!©clear©}§
    4332 int flush( ofstream & );§\indexc{flush}\index{ofstream@©ofstream©!©flush©}§
    4333 void open( ofstream &, const char name[], const char mode[] = "w" );§\indexc{open}\index{ofstream@©ofstream©!©open©}§
    4334 void close( ofstream & );§\indexc{close}\index{ofstream@©ofstream©!©close©}§
    4335 ofstream & write( ofstream &, const char data[], size_t size );§\indexc{write}\index{ofstream@©ofstream©!©write©}§
    4336 
    4337 void ?{}( ofstream & );§\index{ofstream@©ofstream©!©?{}©}§
    4338 void ?{}( ofstream &, const char name[], const char mode[] = "w" );
    4339 void ^?{}( ofstream & );§\index{ofstream@©ofstream©!©^?{}©}§
    4340 
    4341 // *********************************** ifstream ***********************************
    4342 
    4343 bool fail( ifstream & is );§\indexc{fail}\index{ifstream@©ifstream©!©fail©}§
    4344 void clear( ifstream & );§\indexc{clear}\index{ifstream@©ifstream©!©clear©}§
    4345 bool eof( ifstream & is );§\indexc{eof}\index{ifstream@©ifstream©!©eof©}§
    4346 void open( ifstream & is, const char name[], const char mode[] = "r" );§\indexc{open}\index{ifstream@©ifstream©!©open©}§
    4347 void close( ifstream & is );§\indexc{close}\index{ifstream@©ifstream©!©close©}§
    4348 ifstream & read( ifstream & is, char data[], size_t size );§\indexc{read}\index{ifstream@©ifstream©!©read©}§
    4349 ifstream & ungetc( ifstream & is, char c );§\indexc{unget}\index{ifstream@©ifstream©!©unget©}§
    4350 
    4351 void ?{}( ifstream & is );§\index{ifstream@©ifstream©!©?{}©}§
    4352 void ?{}( ifstream & is, const char name[], const char mode[] = "r" );
    4353 void ^?{}( ifstream & is );§\index{ifstream@©ifstream©!©^?{}©}§
    4354 \end{cfa}
    4355 \caption{Stream Functions}
    4356 \label{f:StreamFunctions}
    4357 \end{figure}
    4358 
    43594424
    43604425\subsection{Implicit Separator}
    43614426
    43624427The \Index{implicit separator}\index{I/O!separator} character (space/blank) is a separator not a terminator for output.
    4363 The rules for implicitly adding the separator are:
     4428The rules for implicitly adding a separator are:
    43644429\begin{enumerate}
    43654430\item
     
    43904455\begin{cfa}
    43914456sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    4392            | 7 | "$\LstStringStyle{\textcent}$ x" | 8 | "$\LstStringStyle{\guillemotright}$ x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     4457           | 7 | "§\LstStringStyle{\textcent}§ x" | 8 | "§\LstStringStyle{\guillemotright}§ x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
    43934458\end{cfa}
    43944459\begin{cfa}[showspaces=true]
    4395 1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7$\R{\LstStringStyle{\textcent}}$ x 8$\R{\LstStringStyle{\guillemotright}}$ x 9®)® x 10®]® x 11®}® x
     4460Input1®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\R{\LstStringStyle{\textcent}}§ x 8§\R{\LstStringStyle{\guillemotright}}§ x 9®)® x 10®]® x 11®}® x
    43964461\end{cfa}
    43974462
    43984463\item
    43994464A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \LstStringStyle{([\{=\$\textsterling\textyen\textexclamdown\textquestiondown\guillemotleft}, where \LstStringStyle{\textexclamdown\textquestiondown} are inverted opening exclamation and question marks, and \LstStringStyle{\guillemotleft} is an opening citation mark.
    4400 %$
    4401 \begin{cfa}
    4402 sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $\LstStringStyle{\textdollar}$" | 5 | "x $\LstStringStyle{\textsterling}$" | 6 | "x $\LstStringStyle{\textyen}$"
    4403            | 7 | "x $\LstStringStyle{\textexclamdown}$" | 8 | "x $\LstStringStyle{\textquestiondown}$" | 9 | "x $\LstStringStyle{\guillemotleft}$" | 10;
    4404 \end{cfa}
    4405 %$
     4465\begin{cfa}
     4466sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x §\LstStringStyle{\textdollar}§" | 5 | "x §\LstStringStyle{\textsterling}§" | 6 | "x §\LstStringStyle{\textyen}§"
     4467           | 7 | "x §\LstStringStyle{\textexclamdown}§" | 8 | "x §\LstStringStyle{\textquestiondown}§" | 9 | "x §\LstStringStyle{\guillemotleft}§" | 10;
     4468\end{cfa}
    44064469\begin{cfa}[showspaces=true]
    4407 x ®(®1 x ®[®2 x ®{®3 x ®=®4 x $\LstStringStyle{\textdollar}$5 x $\R{\LstStringStyle{\textsterling}}$6 x $\R{\LstStringStyle{\textyen}}$7 x $\R{\LstStringStyle{\textexclamdown}}$8 x $\R{\LstStringStyle{\textquestiondown}}$9 x $\R{\LstStringStyle{\guillemotleft}}$10
    4408 \end{cfa}
    4409 %$
     4470x ®(®1 x ®[®2 x ®{®3 x ®=®4 x §\LstStringStyle{\textdollar}§5 x §\R{\LstStringStyle{\textsterling}}§6 x §\R{\LstStringStyle{\textyen}}§7 x §\R{\LstStringStyle{\textexclamdown}}§8 x §\R{\LstStringStyle{\textquestiondown}}§9 x §\R{\LstStringStyle{\guillemotleft}}§10
     4471\end{cfa}
    44104472
    44114473\item
     
    44154477\end{cfa}
    44164478\begin{cfa}[showspaces=true,showtabs=true]
    4417 x®`®1®`®x$\R{\texttt{'}}$2$\R{\texttt{'}}$x$\R{\texttt{"}}$3$\R{\texttt{"}}$x®:®4®:®x® ®5® ®x®  ®6®     ®x
     4479x®`®1®`®x§\R{\texttt{'}}§2§\R{\texttt{'}}§x§\R{\texttt{"}}§3§\R{\texttt{"}}§x®:®4®:®x® ®5® ®x®  ®6®     ®x
    44184480\end{cfa}
    44194481
     
    44214483If a space is desired before or after one of the special string start/end characters, explicitly insert a space.
    44224484\begin{cfa}
    4423 sout | "x ($\R{\texttt{\textvisiblespace}}$" | 1 | "$\R{\texttt{\textvisiblespace}}$) x" | 2 | "$\R{\texttt{\textvisiblespace}}$, x" | 3 | "$\R{\texttt{\textvisiblespace}}$:x:$\R{\texttt{\textvisiblespace}}$" | 4;
     4485sout | "x (§\R{\texttt{\textvisiblespace}}§" | 1 | "§\R{\texttt{\textvisiblespace}}§) x" | 2 | "§\R{\texttt{\textvisiblespace}}§, x" | 3 | "§\R{\texttt{\textvisiblespace}}§:x:§\R{\texttt{\textvisiblespace}}§" | 4;
    44244486\end{cfa}
    44254487\begin{cfa}[showspaces=true,showtabs=true]
     
    44384500The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    44394501\begin{cfa}[belowskip=0pt]
    4440 sepSet( sout, ", $\LstStringStyle{\textdollar}$" ); §\C{// set separator from " " to ", \$"}§
     4502sepSet( sout, ", §\LstStringStyle{\textdollar}§" ); §\C{// set separator from " " to ", \$"}§
    44414503sout | 1 | 2 | 3 | " \"" | ®sepVal® | "\"";
    44424504\end{cfa}
    44434505\begin{cfa}[showspaces=true,aboveskip=0pt]
    4444 1®, $\color{red}\LstStringStyle{\textdollar}$®2®, $\color{red}\LstStringStyle{\textdollar}$®3 ®", $\color{red}\LstStringStyle{\textdollar}$
     45061®, §\color{red}\LstStringStyle{\textdollar}§®2®, §\color{red}\LstStringStyle{\textdollar}§®3 ®", §\color{red}\LstStringStyle{\textdollar}§
    44454507\end{cfa}
    44464508\begin{cfa}[belowskip=0pt]
     
    45574619For example, in:
    45584620\begin{cfa}
     4621int i, j;
    45594622sin | i | ®nl® | j;
    456046231 ®2®
     
    45624625\end{cfa}
    45634626variable ©i© is assigned 1, the 2 is skipped, and variable ©j© is assigned 3.
     4627For example, in:
     4628\begin{cquote}
     4629\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     4630\begin{cfa}
     4631char ch
     4632
     4633sin | ch; // read X
     4634
     4635X
     4636\end{cfa}
     4637&
     4638\begin{cfa}
     4639
     4640sin | ®nlOn®; // enable reading newlines
     4641sin | ch; // read newline
     4642
     4643
     4644\end{cfa}
     4645\end{tabular}
     4646\end{cquote}
     4647the left example skips the newline and reads ©'X'© into ©ch©, while the right example reads the newline into ©ch©.
    45644648
    45654649For output:
     
    45894673
    45904674
    4591 \subsection{Output Value Manipulators}
     4675\subsection{Output Manipulators}
    45924676
    45934677The following \Index{manipulator}s control formatting (printing) of the argument output values.
     
    46434727\item
    46444728\Indexc{unit}( engineering-notation )\index{manipulator!unit@©unit©} print engineering exponent as a letter between the range $10^{-24}$ and $10^{24}$:
     4729\begin{cquote}
    46454730©y© $\Rightarrow 10^{-24}$, ©z© $\Rightarrow 10^{-21}$, ©a© $\Rightarrow 10^{-18}$, ©f© $\Rightarrow 10^{-15}$, ©p© $\Rightarrow 10^{-12}$, ©n© $\Rightarrow 10^{-9}$, ©u© $\Rightarrow 10^{-6}$, ©m© $\Rightarrow 10^{-3}$, ©K© $\Rightarrow 10^{3}$, ©M© $\Rightarrow 10^{6}$, ©G© $\Rightarrow 10^{9}$, ©T© $\Rightarrow 10^{12}$, ©P© $\Rightarrow 10^{15}$, ©E© $\Rightarrow 10^{18}$, ©Z© $\Rightarrow 10^{21}$, ©Y© $\Rightarrow 10^{24}$.
     4731\end{cquote}
    46464732For exponent $10^{0}$, no decimal point or letter is printed.
    46474733\begin{cfa}[belowskip=0pt]
     
    48434929// End: //
    48444930\end{comment}
    4845 %$
    4846 
    4847 
    4848 \subsection{Input Value Manipulators}
    4849 
    4850 The format of numeric input values in the same as C constants without a trailing type suffix, as the input value-type is denoted by the input variable.
    4851 For ©bool© type, the constants are ©true© and ©false©.
    4852 For integral types, any number of digits, optionally preceded by a sign (©+© or ©-©), where a
    4853 \begin{itemize}
    4854 \item
    4855 ©1©-©9© prefix introduces a decimal value (©0©-©9©),
    4856 \item
    4857 ©0© prefix introduces an octal value (©0©-©7©), and
    4858 \item
    4859 ©0x© or ©0X© prefix introduces a hexadecimal value (©0©-©f©) with lower or upper case letters.
    4860 \end{itemize}
    4861 For floating-point types, any number of decimal digits, optionally preceded by a sign (©+© or ©-©), optionally containing a decimal point, and optionally followed by an exponent, ©e© or ©E©, with signed (optional) decimal digits.
    4862 Floating-point values can also be written in hexadecimal format preceded by ©0x© or ©0X© with hexadecimal digits and exponent denoted by ©p© or ©P©.
    4863 
    4864 For the C-string type, the input values are \emph{not} the same as C-string constants, \ie double quotes bracketing arbitrary text with escape sequences.
    4865 Instead, the next sequence of non-whitespace characters are read, and the input sequence is terminated with delimiter ©'\0'©.
    4866 The string variable \emph{must} be large enough to contain the input sequence.
     4931
     4932
     4933\subsection{Input Manipulators}
     4934
     4935The following \Index{manipulator}s control scanning of input values (reading), and only affect the format of the argument.
     4936
     4937Certain manipulators support a \newterm{scanset}, which is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus.
     4938For example, the scanset \lstinline{"a-zA-Z -/?§"} matches any number of characters between ©'a'© and ©'z'©, between ©'A'© and ©'Z'©, between space and ©'/'©, and characters ©'?'© and (Latin-1) ©'§'©.
     4939The following string is matched by this scanset:
     4940\begin{cfa}
     4941!&%$  abAA () ZZZ  ??  xx§\S\S\S§
     4942\end{cfa}
     4943To match a minus, put it as the first character, ©"-0-9"©.
     4944Other complex forms of regular-expression matching are not supported.
     4945
     4946A string variable \emph{must} be large enough to contain the input sequence.
    48674947To force programmers to consider buffer overruns for C-string input, C-strings can only be read with a width field, which should specify a size less than or equal to the C-string size, \eg:
    48684948\begin{cfa}
     
    48714951\end{cfa}
    48724952
    4873 A scanset is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus.
    4874 For example, the scanset \lstinline{"a-zA-Z -/?§"} matches characters between ©'a'© and ©'z'©, between ©'A'© and ©'Z'©, between space and ©'/'©, and characters ©'?'© and (Latin-1) ©'§'©.
    4875 The following string is matched by this scanset:
    4876 \begin{cfa}
    4877 !&%$  abAA () ZZZ  ??  xx§§§§
    4878 \end{cfa}
    4879 To match a minus, put it as the first character, ©"-0-9"©.
    4880 Other complex forms of regular-expression matching are not supported.
    4881 
    4882 The following \Index{manipulator}s control scanning of input values (reading), and only affect the format of the argument.
     4953Currently, there is no mechanism to detect if a value read exceeds the capwhen Most types are finite sized, \eg integral types only store value that fit into their corresponding storage, 8, 16, 32, 64, 128 bits.
     4954Hence, an input value may be too large, and the result of the read is often considered undefined, which leads to difficlt to locate runtime errors.
     4955All reads in \CFA check if values do not fit into the argument variable's type and raise the exception
     4956All types are
     4957
    48834958\begin{enumerate}
    48844959\item
    4885 \Indexc{skip}( pattern )\index{manipulator!skip@©skip©}, ©skip©( length )
    4886 The pattern is composed of white-space and non-white-space characters, where \emph{any} white-space character matches 0 or more input white-space characters (hence, consecutive white-space characters in the pattern are combined), and each non-white-space character matches exactly with an input character.
    4887 The length is composed of the next $N$ characters, including the newline character.
     4960\Indexc{skip}( scanset )\index{manipulator!skip@©skip©}, ©skip©( $N$ )
     4961The first form uses a scanset to skip matching characters.
     4962The second form skips the next $N$ characters, including newline.
    48884963If the match successes, the input characters are discarded, and input continues with the next character.
    48894964If the match fails, the input characters are left unread.
    48904965\begin{cfa}[belowskip=0pt]
    4891 char sk[$\,$] = "abc";
     4966char sk[§\,§] = "abc";
    48924967sin | "abc " | skip( sk ) | skip( 5 ); // match input sequence
    48934968\end{cfa}
     
    48994974
    49004975\item
    4901 \Indexc{wdi}( maximum, reference-value )\index{manipulator!wdi@©wdi©}
    4902 For all types except ©char©, maximum is the maximum number of characters read for the current operation.
     4976\Indexc{wdi}( maximum, variable )\index{manipulator!wdi@©wdi©}
     4977For all types except ©char *©, whitespace is skipped until an appropriate value is found for the specified variable type.
     4978maximum is the maximum number of characters read for the current operation.
    49034979\begin{cfa}[belowskip=0pt]
    4904 char s[10];   int i;   double d;   
    4905 sin | wdi( 4, s ) | wdi( 3, i ) | wdi( 8, d );  // c == "abcd", i == 123, d == 3.456E+2
     4980char ch;   char ca[3];   int i;   double d;   
     4981sin | wdi( sizeof(ch), ch ) | wdi( sizeof(ca), ca[0] ) | wdi( 3, i ) | wdi( 8, d );  // c == 'a', ca == "bcd", i == 123, d == 345.6
    49064982\end{cfa}
    49074983\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    49084984®abcd1233.456E+2®
    49094985\end{cfa}
     4986Here, ©ca[0]© is type ©char©, so the width reads 3 characters \Textbf{without} a null terminator.
     4987
    49104988Note, input ©wdi© cannot be overloaded with output ©wd© because both have the same parameters but return different types.
    49114989Currently, \CFA cannot distinguish between these two manipulators in the middle of an ©sout©/©sin© expression based on return type.
     4990
     4991\item
     4992\Indexc{wdi}( maximum size, ©char s[]© )\index{manipulator!wdi@©wdi©}
     4993For type ©char *©, maximum is the maximum number of characters read for the current operation.
     4994Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence
     4995\begin{cfa}[belowskip=0pt]
     4996char cstr[10];
     4997sin | wdi( sizeof(cstr), cstr );
     4998\end{cfa}
     4999\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     5000®abcd1233.456E+2®
     5001\end{cfa}
     5002
     5003\item
     5004\Indexc{wdi}( maximum size, maximum read, ©char s[]© )\index{manipulator!wdi@©wdi©}
     5005For type ©char *©, maximum is the maximum number of characters read for the current operation.
     5006\begin{cfa}[belowskip=0pt]
     5007char ch;   char ca[3];   int i;   double d;   
     5008sin | wdi( sizeof(ch), ch ) | wdi( sizeof(ca), ca[0] ) | wdi( 3, i ) | wdi( 8, d );  // c == 'a', ca == "bcd", i == 123, d == 345.6
     5009\end{cfa}
     5010\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     5011®abcd1233.456E+2®
     5012\end{cfa}
    49125013
    49135014\item
     
    49465047\end{cfa}
    49475048
     5049\Indexc{quoted}( char delimit, wdi-input-string )\index{manipulator!quoted@©quoted©}
     5050Is an ©excl© with scanset ©"delimit"©, which consumes all characters up to the delimit character.
     5051If the delimit character is omitted, it defaults to ©'\n'© (newline).
     5052
    49485053\item
    49495054\Indexc{getline}( char delimit, wdi-input-string )\index{manipulator!getline@©getline©}
    4950 Is an @excl@ with scanset ©"delimit"©, which consumes all characters up to the delimit character.
     5055Is an ©excl© with scanset ©"delimit"©, which consumes all characters up to the delimit character.
    49515056If the delimit character is omitted, it defaults to ©'\n'© (newline).
    49525057\end{enumerate}
     
    49585063For example, if two threads execute the following:
    49595064\begin{cfa}
    4960 $\emph{thread\(_1\)}$ : sout | "abc " | "def ";
    4961 $\emph{thread\(_2\)}$ : sout | "uvw " | "xyz ";
     5065§\emph{thread\(_1\)}§ : sout | "abc " | "def ";
     5066§\emph{thread\(_2\)}§ : sout | "uvw " | "xyz ";
    49625067\end{cfa}
    49635068possible outputs are:
     
    49995104The common usage is the short form of the mutex statement\index{ostream@©ostream©!mutex@©mutex©} to lock a stream during a single cascaded I/O expression, \eg:
    50005105\begin{cfa}
    5001 $\emph{thread\(_1\)}$ : ®mutex( sout )® sout | "abc " | "def ";
    5002 $\emph{thread\(_2\)}$ : ®mutex( sout )® sout | "uvw " | "xyz ";
     5106§\emph{thread\(_1\)}§ : ®mutex( sout )® sout | "abc " | "def ";
     5107§\emph{thread\(_2\)}§ : ®mutex( sout )® sout | "uvw " | "xyz ";
    50035108\end{cfa}
    50045109Now, the order of the thread execution is still non-deterministic, but the output is constrained to two possible lines in either order.
     
    50615166Cultures use different syntax, called a \newterm{locale}, for printing numbers so they are easier to read, \eg:
    50625167\begin{cfa}
    5063 12®,®345®.®123          $\C[1.25in]{// comma separator, period decimal-point}$
     516812®,®345®.®123          §\C[1.25in]{// comma separator, period decimal-point}§
    5064516912®.®345®,®123          §\C{// period separator, comma decimal-point}§
    5065 12$\Sp$345®,®123®.®     §\C{// space separator, comma decimal-point, period terminator}\CRT§
     517012§\Sp§345®,®123®.®     §\C{// space separator, comma decimal-point, period terminator}\CRT§
    50665171\end{cfa}
    50675172A locale is selected with function ©setlocale©, and the corresponding locale package \emph{must} be installed on the underlying system;
     
    51095214Ukraine uk_UA.utf8
    5110521512 123 1 234 12 345 123 456 1 234 567
    5111 12®.® 123®,®1®.® 1$\Sp$234®,®12®.® 12$\Sp$ 345®,®123®.® 123$\Sp$ 456®,®1234®.® 1$\Sp$ 234$\Sp$567®,®12345®.®
     521612®.® 123®,®1®.® 1§\Sp§234®,®12®.® 12§\Sp§ 345®,®123®.® 123§\Sp§ 456®,®1234®.® 1§\Sp§ 234§\Sp§567®,®12345®.®
    51125217
    51135218Default locale off C
     
    54615566
    54625567\subsection{Operator}
     5568\label{s:Operator}
    54635569
    54645570\CFA also allows operators to be overloaded, to simplify the use of user-defined types.
     
    73327438
    73337439\Index*[C++]{\CC{}} is a general-purpose programming language.
    7334 It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation. (Wikipedia)
    7335 
    7336 The primary focus of \CC seems to be adding object-oriented programming to C, and this is the primary difference between \CC and Do.
     7440It is an imperative, object-oriented and generic programming language, while also providing facilities for low-level memory manipulation.
     7441The primary focus of \CC was adding object-oriented programming to C, and this is the primary difference between \CC and \CFA.
    73377442\CC uses classes to encapsulate data and the functions that operate on that data, and to hide the internal representation of the data.
    73387443\CFA uses modules instead to perform these same tasks.
     
    73527457\subsection{Go}
    73537458
    7354 \Index*{Go}, also commonly referred to as golang, is a programming language developed at Google in 2007 [.].
     7459\Index*{Go}, also commonly referred to as golang, is a programming language developed at Google in 2007~\cite{Go}.
    73557460It is a statically typed language with syntax loosely derived from that of C, adding garbage collection, type
    73567461safety, some structural typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library. (Wikipedia)
     
    74067511In \CFA, there are ambiguous cases with dereference and operator identifiers, \eg ©int *?*?()©, where the string ©*?*?© can be interpreted as:
    74077512\begin{cfa}
    7408 *?$\Sp$*? §\C{// dereference operator, dereference operator}§
    7409 *$\Sp$?*? §\C{// dereference, multiplication operator}§
     7513*?§\Sp§*?                                                               §\C{// dereference operator, dereference operator}§
     7514*§\Sp§?*?                                                               §\C{// dereference, multiplication operator}§
    74107515\end{cfa}
    74117516By default, the first interpretation is selected, which does not yield a meaningful parse.
     
    74167521The ambiguity occurs when the deference operator has no parameters:
    74177522\begin{cfa}
    7418 *?()$\R{\textvisiblespace...}$ ;
    7419 *?()$\R{\textvisiblespace...}$(...) ;
     7523*?()§\R{\textvisiblespace...}§ ;
     7524*?()§\R{\textvisiblespace...}§(...) ;
    74207525\end{cfa}
    74217526requiring arbitrary whitespace look-ahead for the routine-call parameter-list to disambiguate.
     
    74257530The remaining cases are with the increment/decrement operators and conditional expression, \eg:
    74267531\begin{cfa}
    7427 i++?$\R{\textvisiblespace...}$(...);
    7428 i?++$\R{\textvisiblespace...}$(...);
     7532i++?§\R{\textvisiblespace...}§(...);
     7533i?++§\R{\textvisiblespace...}§(...);
    74297534\end{cfa}
    74307535requiring arbitrary whitespace look-ahead for the operator parameter-list, even though that interpretation is an incorrect expression (juxtaposed identifiers).
    74317536Therefore, it is necessary to disambiguate these cases with a space:
    74327537\begin{cfa}
    7433 i++$\Sp$? i : 0;
    7434 i?$\Sp$++i : 0;
     7538i++§\Sp§? i : 0;
     7539i?§\Sp§++i : 0;
    74357540\end{cfa}
    74367541
     
    74597564\eg:
    74607565\begin{cfa}
    7461 x; §\C{// int x}§
    7462 *y; §\C{// int *y}§
    7463 f( p1, p2 ); §\C{// int f( int p1, int p2 );}§
    7464 g( p1, p2 ) int p1, p2; §\C{// int g( int p1, int p2 );}§
     7566x;                                                              §\C{// int x}§
     7567*y;                                                             §\C{// int * y}§
     7568f( p1, p2 );                                    §\C{// int f( int p1, int p2 );}§
     7569g( p1, p2 ) int p1, p2;                 §\C{// int g( int p1, int p2 );}§
    74657570\end{cfa}
    74667571\CFA continues to support K\&R routine definitions:
    74677572\begin{cfa}
    7468 f( a, b, c ) §\C{// default int return}§
    7469         int a, b; char c §\C{// K\&R parameter declarations}§
     7573f( a, b, c )                                    §\C{// default int return}§
     7574        int a, b; char c;                       §\C{// K\&R parameter declarations}§
    74707575{
    74717576        ...
     
    74867591int rtn( int i );
    74877592int rtn( char c );
    7488 rtn( 'x' ); §\C{// programmer expects 2nd rtn to be called}§
     7593rtn( 'x' );                                             §\C{// programmer expects 2nd rtn to be called}§
    74897594\end{cfa}
    74907595\item[Rationale:] it is more intuitive for the call to ©rtn© to match the second version of definition of ©rtn© rather than the first.
     
    75087613\item[Change:] make string literals ©const©:
    75097614\begin{cfa}
    7510 char * p = "abc"; §\C{// valid in C, deprecated in \CFA}§
    7511 char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
     7615char * p = "abc";                               §\C{// valid in C, deprecated in \CFA}§
     7616char * q = expr ? "abc" : "de"; §\C{// valid in C, invalid in \CFA}§
    75127617\end{cfa}
    75137618The type of a string literal is changed from ©[] char© to ©const [] char©.
     
    75167621\begin{cfa}
    75177622char * p = "abc";
    7518 p[0] = 'w'; §\C{// segment fault or change constant literal}§
     7623p[0] = 'w';                                             §\C{// segment fault or change constant literal}§
    75197624\end{cfa}
    75207625The same problem occurs when passing a string literal to a routine that changes its argument.
     
    75287633\item[Change:] remove \newterm{tentative definitions}, which only occurs at file scope:
    75297634\begin{cfa}
    7530 int i; §\C{// forward definition}§
    7531 int *j = ®&i®; §\C{// forward reference, valid in C, invalid in \CFA}§
    7532 int i = 0; §\C{// definition}§
     7635int i;                                                  §\C{// forward definition}§
     7636int *j = ®&i®;                                  §\C{// forward reference, valid in C, invalid in \CFA}§
     7637int i = 0;                                              §\C{// definition}§
    75337638\end{cfa}
    75347639is valid in C, and invalid in \CFA because duplicate overloaded object definitions at the same scope level are disallowed.
     
    75367641\begin{cfa}
    75377642struct X { int i; struct X *next; };
    7538 static struct X a; §\C{// forward definition}§
    7539 static struct X b = { 0, ®&a® };§\C{// forward reference, valid in C, invalid in \CFA}§
    7540 static struct X a = { 1, &b }; §\C{// definition}§
     7643static struct X a;                              §\C{// forward definition}§
     7644static struct X b = { 0, ®&a® }; §\C{// forward reference, valid in C, invalid in \CFA}§
     7645static struct X a = { 1, &b };  §\C{// definition}§
    75417646\end{cfa}
    75427647\item[Rationale:] avoids having different initialization rules for builtin types and user-defined types.
     
    75527657enum ®Colour® { R, G, B, Y, C, M };
    75537658struct Person {
    7554         enum ®Colour® { R, G, B };      $\C[7cm]{// nested type}$
    7555         struct Face { §\C{// nested type}§
    7556                 ®Colour® Eyes, Hair; §\C{// type defined outside (1 level)}§
     7659        enum ®Colour® { R, G, B };      §\C{// nested type}§
     7660        struct Face {                           §\C{// nested type}§
     7661                ®Colour® Eyes, Hair;    §\C{// type defined outside (1 level)}§
    75577662        };
    7558         ®.Colour® shirt; §\C{// type defined outside (top level)}§
    7559         ®Colour® pants; §\C{// type defined same level}§
    7560         Face looks[10]; §\C{// type defined same level}§
     7663        ®.Colour® shirt;                        §\C{// type defined outside (top level)}§
     7664        ®Colour® pants;                         §\C{// type defined same level}§
     7665        Face looks[10];                         §\C{// type defined same level}§
    75617666};
    7562 ®Colour® c = R; §\C{// type/enum defined same level}§
    7563 Person®.Colour® pc = Person®.®R;§\C{// type/enum defined inside}§
    7564 Person®.®Face pretty; §\C{// type defined inside}\CRT§
     7667®Colour® c = R;                                 §\C{// type/enum defined same level}§
     7668Person®.Colour® pc = Person®.®R;        §\C{// type/enum defined inside}§
     7669Person®.®Face pretty;                   §\C{// type defined inside}§
    75657670\end{cfa}
    75667671In C, the name of the nested types belongs to the same scope as the name of the outermost enclosing structure, \ie the nested types are hoisted to the scope of the outer-most type, which is not useful and confusing.
     
    76397744\CFA introduces the following new \Index{keyword}s, which cannot be used as identifiers.
    76407745
     7746\begin{cquote}
     7747\Indexc{basetypeof}, \Indexc{choose}, \Indexc{coroutine}, \Indexc{disable},
     7748\Indexc{enable}, \Indexc{exception}, \Indexc{fallthrough}, \Indexc{fallthru},
     7749\Indexc{finally}, \Indexc{fixup}, \Indexc{forall},\Indexc{generator},
     7750\Indexc{int128}, \Indexc{monitor}, \Indexc{mutex}, \Indexc{one_t},
     7751\Indexc{report}, \Indexc{suspend}, \Indexc{throw}, \Indexc{throwResume},
     7752\Indexc{trait}, \Indexc{try}, \Indexc{virtual}, \Indexc{waitfor},
     7753\Indexc{when}, \Indexc{with}, \Indexc{zero_t}
     7754\end{cquote}
     7755\CFA introduces the following new \Index{quasi-keyword}s, which can be used as identifiers.
     7756\begin{cquote}
     7757\Indexc{catch}, \Indexc{catchResume}, \Indexc{finally}, \Indexc{fixup}, \Indexc{or}, \Indexc{timeout}
     7758\end{cquote}
     7759
     7760\begin{comment}
    76417761\begin{cquote}
    76427762\begin{tabular}{@{}lllllll@{}}
     
    77077827\end{tabular}
    77087828\end{cquote}
     7829\end{comment}
     7830
    77097831
    77107832\section{Standard Headers}
    77117833\label{s:StandardHeaders}
    77127834
    7713 \Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11} and \CFA adds to this list:
     7835\Celeven prescribes the following standard header-files~\cite[\S~7.1.2]{C11}:
     7836\begin{cquote}
     7837\Indexc{assert.h}, \Indexc{complex.h}, \Indexc{ctype.h}, \Indexc{errno.h}, \Indexc{fenv.h},
     7838\Indexc[deletekeywords=float]{float.h}, \Indexc{inttypes.h}, \Indexc{iso646.h}, \Indexc{limits.h},
     7839\Indexc{locale.h}, \Indexc{math.h}, \Indexc{setjmp.h}, \Indexc{signal.h}, \Indexc{stdalign.h},
     7840\Indexc{stdarg.h}, \Indexc{stdatomic.h}, \Indexc{stdbool.h}, \Indexc{stddef.h}, \Indexc{stdint.h},
     7841\Indexc{stdio.h}, \Indexc{stdlib.h}, \Indexc{stdnoreturn.h}, \Indexc{string.h}, \Indexc{tgmath.h},
     7842\Indexc{threads.h}, \Indexc{time.h}, \Indexc{uchar.h}, \Indexc{wchar.h}, \Indexc{wctype.h}
     7843\end{cquote}
     7844and \CFA adds to this list:
     7845\begin{cquote}
     7846\Indexc{gmp.h}, \Indexc{malloc.h}, \Indexc{unistd.h}
     7847\end{cquote}
     7848\begin{comment}
    77147849\begin{cquote}
    77157850\begin{tabular}{@{}llllll|l@{}}
     
    77737908\end{tabular}
    77747909\end{cquote}
     7910\end{comment}
    77757911For the prescribed head-files, \CFA uses header interposition to wraps these includes in an ©extern "C"©;
    77767912hence, names in these include files are not mangled\index{mangling!name} \see{\VRef{s:Interoperability}}.
     
    78377973Type-safe allocation is provided for all C allocation routines and new \CFA allocation routines, \eg in
    78387974\begin{cfa}
    7839 int * ip = (int *)malloc( sizeof(int) );                §\C{// C}§
    7840 int * ip = malloc();                                                    §\C{// \CFA type-safe version of C malloc}§
    7841 int * ip = alloc();                                                             §\C{// \CFA type-safe uniform alloc}§
     7975int * ip = (int *)malloc( sizeof(int) ); §\C{// C}§
     7976int * ip = malloc();                                    §\C{// \CFA type-safe version of C malloc}§
     7977int * ip = alloc();                                             §\C{// \CFA type-safe uniform alloc}§
    78427978\end{cfa}
    78437979the latter two allocations determine the allocation size from the type of ©p© (©int©) and cast the pointer to the allocated storage to ©int *©.
     
    78467982\begin{cfa}
    78477983struct S { int i; } __attribute__(( aligned( 128 ) )); // cache-line alignment
    7848 S * sp = malloc();                                                              §\C{// honour type alignment}§
     7984S * sp = malloc();                                              §\C{// honour type alignment}§
    78497985\end{cfa}
    78507986the storage allocation is implicitly aligned to 128 rather than the default 16.
     
    78617997\CFA memory management extends allocation to support constructors for initialization of allocated storage, \eg in
    78627998\begin{cfa}
    7863 struct S { int i; };                                                    §\C{// cache-line alignment}§
     7999struct S { int i; };                                    §\C{// cache-line alignment}§
    78648000void ?{}( S & s, int i ) { s.i = i; }
    78658001// assume ?|? operator for printing an S
    78668002
    7867 S & sp = *®new®( 3 );                                                   §\C{// call constructor after allocation}§
     8003S & sp = *®new®( 3 );                                   §\C{// call constructor after allocation}§
    78688004sout | sp.i;
    78698005®delete®( &sp );
    78708006
    7871 S * spa = ®anew®( 10, 5 );                                              §\C{// allocate array and initialize each array element}§
     8007S * spa = ®anew®( 10, 5 );                              §\C{// allocate array and initialize each array element}§
    78728008for ( i; 10 ) sout | spa[i] | nonl;
    78738009sout | nl;
     
    78818017extern "C" {
    78828018        // C unsafe allocation
    7883         void * malloc( size_t size );$\indexc{malloc}$
    7884         void * calloc( size_t dim, size_t size );$\indexc{calloc}$
    7885         void * realloc( void * ptr, size_t size );$\indexc{realloc}$
    7886         void * memalign( size_t align, size_t size );$\indexc{memalign}$
    7887         void * aligned_alloc( size_t align, size_t size );$\indexc{aligned_alloc}$
    7888         int posix_memalign( void ** ptr, size_t align, size_t size );$\indexc{posix_memalign}$
    7889         void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );$\indexc{cmemalign}$ // CFA
     8019        void * malloc( size_t size );§\indexc{malloc}§
     8020        void * calloc( size_t dim, size_t size );§\indexc{calloc}§
     8021        void * realloc( void * ptr, size_t size );§\indexc{realloc}§
     8022        void * memalign( size_t align, size_t size );§\indexc{memalign}§
     8023        void * aligned_alloc( size_t align, size_t size );§\indexc{aligned_alloc}§
     8024        int posix_memalign( void ** ptr, size_t align, size_t size );§\indexc{posix_memalign}§
     8025        void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize );§\indexc{cmemalign}§ // CFA
    78908026
    78918027        // C unsafe initialization/copy
    7892         void * memset( void * dest, int c, size_t size );$\indexc{memset}$
    7893         void * memcpy( void * dest, const void * src, size_t size );$\indexc{memcpy}$
     8028        void * memset( void * dest, int c, size_t size );§\indexc{memset}§
     8029        void * memcpy( void * dest, const void * src, size_t size );§\indexc{memcpy}§
    78948030}
    78958031
     
    78978033
    78988034forall( dtype T | sized(T) ) {
    7899         // $\CFA$ safe equivalents, i.e., implicit size specification
     8035        // §\CFA§ safe equivalents, i.e., implicit size specification
    79008036        T * malloc( void );
    79018037        T * calloc( size_t dim );
     
    79068042        int posix_memalign( T ** ptr, size_t align );
    79078043
    7908         // $\CFA$ safe general allocation, fill, resize, alignment, array
    7909         T * alloc( void );$\indexc{alloc}$                                      $\C[3.5in]{// variable, T size}$
     8044        // §\CFA§ safe general allocation, fill, resize, alignment, array
     8045        T * alloc( void );§\indexc{alloc}§                                      §\C[3.5in]{// variable, T size}§
    79108046        T * alloc( size_t dim );                                                        §\C{// array[dim], T size elements}§
    79118047        T * alloc( T ptr[], size_t dim );                                       §\C{// realloc array[dim], T size elements}§
    79128048
    7913         T * alloc_set( char fill );$\indexc{alloc_set}$         §\C{// variable, T size, fill bytes with value}§
     8049        T * alloc_set( char fill );§\indexc{alloc_set}§         §\C{// variable, T size, fill bytes with value}§
    79148050        T * alloc_set( T fill );                                                        §\C{// variable, T size, fill with value}§
    79158051        T * alloc_set( size_t dim, char fill );                         §\C{// array[dim], T size elements, fill bytes with value}§
     
    79308066        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); §\C{// realloc new aligned array[dim], fill new bytes with value}§
    79318067
    7932         // $\CFA$ safe initialization/copy, i.e., implicit size specification
    7933         T * memset( T * dest, char fill );$\indexc{memset}$
    7934         T * memcpy( T * dest, const T * src );$\indexc{memcpy}$
    7935 
    7936         // $\CFA$ safe initialization/copy, i.e., implicit size specification, array types
     8068        // §\CFA§ safe initialization/copy, i.e., implicit size specification
     8069        T * memset( T * dest, char fill );§\indexc{memset}§
     8070        T * memcpy( T * dest, const T * src );§\indexc{memcpy}§
     8071
     8072        // §\CFA§ safe initialization/copy, i.e., implicit size specification, array types
    79378073        T * amemset( T dest[], char fill, size_t dim );
    79388074        T * amemcpy( T dest[], const T src[], size_t dim );
    79398075}
    79408076
    7941 // $\CFA$ allocation/deallocation and constructor/destructor, non-array types
    7942 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );$\indexc{new}$
    7943 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );$\indexc{delete}$
     8077// §\CFA§ allocation/deallocation and constructor/destructor, non-array types
     8078forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * new( Params p );§\indexc{new}§
     8079forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void delete( T * ptr );§\indexc{delete}§
    79448080forall( dtype T, ttype Params | sized(T) | { void ^?{}( T & ); void delete( Params ); } )
    79458081  void delete( T * ptr, Params rest );
    79468082
    7947 // $\CFA$ allocation/deallocation and constructor/destructor, array types
    7948 forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );$\indexc{anew}$
    7949 forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );$\indexc{adelete}$
     8083// §\CFA§ allocation/deallocation and constructor/destructor, array types
     8084forall( dtype T | sized(T), ttype Params | { void ?{}( T &, Params ); } ) T * anew( size_t dim, Params p );§\indexc{anew}§
     8085forall( dtype T | sized(T) | { void ^?{}( T & ); } ) void adelete( size_t dim, T arr[] );§\indexc{adelete}§
    79508086forall( dtype T | sized(T) | { void ^?{}( T & ); }, ttype Params | { void adelete( Params ); } )
    79518087  void adelete( size_t dim, T arr[], Params rest );
     
    79578093\leavevmode
    79588094\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7959 int ato( const char * ptr );$\indexc{ato}$
     8095int ato( const char * ptr );§\indexc{ato}§
    79608096unsigned int ato( const char * ptr );
    79618097long int ato( const char * ptr );
     
    79908126\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    79918127forall( T | { int ?<?( T, T ); } ) §\C{// location}§
    7992 T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$
     8128T * bsearch( T key, const T * arr, size_t dim );§\indexc{bsearch}§
    79938129
    79948130forall( T | { int ?<?( T, T ); } ) §\C{// position}§
     
    79968132
    79978133forall( T | { int ?<?( T, T ); } )
    7998 void qsort( const T * arr, size_t dim );$\indexc{qsort}$
     8134void qsort( const T * arr, size_t dim );§\indexc{qsort}§
    79998135
    80008136forall( E | { int ?<?( E, E ); } ) {
    8001         E * bsearch( E key, const E * vals, size_t dim );$\indexc{bsearch}$ §\C{// location}§
     8137        E * bsearch( E key, const E * vals, size_t dim );§\indexc{bsearch}§ §\C{// location}§
    80028138        size_t bsearch( E key, const E * vals, size_t dim );§\C{// position}§
    8003         E * bsearchl( E key, const E * vals, size_t dim );$\indexc{bsearchl}$
     8139        E * bsearchl( E key, const E * vals, size_t dim );§\indexc{bsearchl}§
    80048140        size_t bsearchl( E key, const E * vals, size_t dim );
    8005         E * bsearchu( E key, const E * vals, size_t dim );$\indexc{bsearchu}$
     8141        E * bsearchu( E key, const E * vals, size_t dim );§\indexc{bsearchu}§
    80068142        size_t bsearchu( E key, const E * vals, size_t dim );
    80078143}
     
    80178153
    80188154forall( E | { int ?<?( E, E ); } ) {
    8019         void qsort( E * vals, size_t dim );$\indexc{qsort}$
     8155        void qsort( E * vals, size_t dim );§\indexc{qsort}§
    80208156}
    80218157\end{cfa}
     
    80268162\leavevmode
    80278163\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8028 unsigned char abs( signed char );$\indexc{abs}$
     8164unsigned char abs( signed char );§\indexc{abs}§
    80298165int abs( int );
    80308166unsigned long int abs( long int );
     
    80418177
    80428178
    8043 \subsection{Random Numbers}
     8179\subsection{C Random Numbers}
    80448180
    80458181\leavevmode
    80468182\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8047 void srandom( unsigned int seed );$\indexc{srandom}$
    8048 char random( void );$\indexc{random}$
     8183void srandom( unsigned int seed );§\indexc{srandom}§
     8184char random( void );§\indexc{random}§
    80498185char random( char u ); §\C{// [0,u)}§
    80508186char random( char l, char u ); §\C{// [l,u]}§
     
    80738209\leavevmode
    80748210\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8075 forall( T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
    8076 forall( T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
    8077 forall( T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
    8078 forall( T ) void swap( T * t1, T * t2 );$\indexc{swap}$
     8211forall( T | { int ?<?( T, T ); } ) T min( T t1, T t2 );§\indexc{min}§
     8212forall( T | { int ?>?( T, T ); } ) T max( T t1, T t2 );§\indexc{max}§
     8213forall( T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );§\indexc{clamp}§
     8214forall( T ) void swap( T * t1, T * t2 );§\indexc{swap}§
    80798215\end{cfa}
    80808216
     
    80908226\leavevmode
    80918227\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8092 float ?%?( float, float );$\indexc{fmod}$
     8228float ?%?( float, float );§\indexc{fmod}§
    80938229float fmod( float, float );
    80948230double ?%?( double, double );
     
    80978233long double fmod( long double, long double );
    80988234
    8099 float remainder( float, float );$\indexc{remainder}$
     8235float remainder( float, float );§\indexc{remainder}§
    81008236double remainder( double, double );
    81018237long double remainder( long double, long double );
    81028238
    8103 float remquo( float, float, int * );$\indexc{remquo}$
     8239float remquo( float, float, int * );§\indexc{remquo}§
    81048240double remquo( double, double, int * );
    81058241long double remquo( long double, long double, int * );
     
    81128248[ int, long double ] div( long double, long double );
    81138249
    8114 float fma( float, float, float );$\indexc{fma}$
     8250float fma( float, float, float );§\indexc{fma}§
    81158251double fma( double, double, double );
    81168252long double fma( long double, long double, long double );
    81178253
    8118 float fdim( float, float );$\indexc{fdim}$
     8254float fdim( float, float );§\indexc{fdim}§
    81198255double fdim( double, double );
    81208256long double fdim( long double, long double );
    81218257
    8122 float nan( const char * );$\indexc{nan}$
     8258float nan( const char * );§\indexc{nan}§
    81238259double nan( const char * );
    81248260long double nan( const char * );
     
    81308266\leavevmode
    81318267\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8132 float exp( float );$\indexc{exp}$
     8268float exp( float );§\indexc{exp}§
    81338269double exp( double );
    81348270long double exp( long double );
     
    81378273long double _Complex exp( long double _Complex );
    81388274
    8139 float exp2( float );$\indexc{exp2}$
     8275float exp2( float );§\indexc{exp2}§
    81408276double exp2( double );
    81418277long double exp2( long double );
     
    81448280// long double _Complex exp2( long double _Complex );
    81458281
    8146 float expm1( float );$\indexc{expm1}$
     8282float expm1( float );§\indexc{expm1}§
    81478283double expm1( double );
    81488284long double expm1( long double );
    81498285
    8150 float pow( float, float );$\indexc{pow}$
     8286float pow( float, float );§\indexc{pow}§
    81518287double pow( double, double );
    81528288long double pow( long double, long double );
     
    81618297\leavevmode
    81628298\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8163 float log( float );$\indexc{log}$
     8299float log( float );§\indexc{log}§
    81648300double log( double );
    81658301long double log( long double );
     
    81688304long double _Complex log( long double _Complex );
    81698305
    8170 int log2( unsigned int );$\indexc{log2}$
     8306int log2( unsigned int );§\indexc{log2}§
    81718307long int log2( unsigned long int );
    81728308long long int log2( unsigned long long int )
     
    81788314// long double _Complex log2( long double _Complex );
    81798315
    8180 float log10( float );$\indexc{log10}$
     8316float log10( float );§\indexc{log10}§
    81818317double log10( double );
    81828318long double log10( long double );
     
    81858321// long double _Complex log10( long double _Complex );
    81868322
    8187 float log1p( float );$\indexc{log1p}$
     8323float log1p( float );§\indexc{log1p}§
    81888324double log1p( double );
    81898325long double log1p( long double );
    81908326
    8191 int ilogb( float );$\indexc{ilogb}$
     8327int ilogb( float );§\indexc{ilogb}§
    81928328int ilogb( double );
    81938329int ilogb( long double );
    81948330
    8195 float logb( float );$\indexc{logb}$
     8331float logb( float );§\indexc{logb}§
    81968332double logb( double );
    81978333long double logb( long double );
    81988334
    8199 float sqrt( float );$\indexc{sqrt}$
     8335float sqrt( float );§\indexc{sqrt}§
    82008336double sqrt( double );
    82018337long double sqrt( long double );
     
    82048340long double _Complex sqrt( long double _Complex );
    82058341
    8206 float cbrt( float );$\indexc{cbrt}$
     8342float cbrt( float );§\indexc{cbrt}§
    82078343double cbrt( double );
    82088344long double cbrt( long double );
    82098345
    8210 float hypot( float, float );$\indexc{hypot}$
     8346float hypot( float, float );§\indexc{hypot}§
    82118347double hypot( double, double );
    82128348long double hypot( long double, long double );
     
    82188354\leavevmode
    82198355\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8220 float sin( float );$\indexc{sin}$
     8356float sin( float );§\indexc{sin}§
    82218357double sin( double );
    82228358long double sin( long double );
     
    82258361long double _Complex sin( long double _Complex );
    82268362
    8227 float cos( float );$\indexc{cos}$
     8363float cos( float );§\indexc{cos}§
    82288364double cos( double );
    82298365long double cos( long double );
     
    82328368long double _Complex cos( long double _Complex );
    82338369
    8234 float tan( float );$\indexc{tan}$
     8370float tan( float );§\indexc{tan}§
    82358371double tan( double );
    82368372long double tan( long double );
     
    82398375long double _Complex tan( long double _Complex );
    82408376
    8241 float asin( float );$\indexc{asin}$
     8377float asin( float );§\indexc{asin}§
    82428378double asin( double );
    82438379long double asin( long double );
     
    82468382long double _Complex asin( long double _Complex );
    82478383
    8248 float acos( float );$\indexc{acos}$
     8384float acos( float );§\indexc{acos}§
    82498385double acos( double );
    82508386long double acos( long double );
     
    82538389long double _Complex acos( long double _Complex );
    82548390
    8255 float atan( float );$\indexc{atan}$
     8391float atan( float );§\indexc{atan}§
    82568392double atan( double );
    82578393long double atan( long double );
     
    82608396long double _Complex atan( long double _Complex );
    82618397
    8262 float atan2( float, float );$\indexc{atan2}$
     8398float atan2( float, float );§\indexc{atan2}§
    82638399double atan2( double, double );
    82648400long double atan2( long double, long double );
    82658401
    82668402float atan( float, float ); §\C{// alternative name for atan2}§
    8267 double atan( double, double );$\indexc{atan}$
     8403double atan( double, double );§\indexc{atan}§
    82688404long double atan( long double, long double );
    82698405\end{cfa}
     
    82748410\leavevmode
    82758411\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8276 float sinh( float );$\indexc{sinh}$
     8412float sinh( float );§\indexc{sinh}§
    82778413double sinh( double );
    82788414long double sinh( long double );
     
    82818417long double _Complex sinh( long double _Complex );
    82828418
    8283 float cosh( float );$\indexc{cosh}$
     8419float cosh( float );§\indexc{cosh}§
    82848420double cosh( double );
    82858421long double cosh( long double );
     
    82888424long double _Complex cosh( long double _Complex );
    82898425
    8290 float tanh( float );$\indexc{tanh}$
     8426float tanh( float );§\indexc{tanh}§
    82918427double tanh( double );
    82928428long double tanh( long double );
     
    82958431long double _Complex tanh( long double _Complex );
    82968432
    8297 float asinh( float );$\indexc{asinh}$
     8433float asinh( float );§\indexc{asinh}§
    82988434double asinh( double );
    82998435long double asinh( long double );
     
    83028438long double _Complex asinh( long double _Complex );
    83038439
    8304 float acosh( float );$\indexc{acosh}$
     8440float acosh( float );§\indexc{acosh}§
    83058441double acosh( double );
    83068442long double acosh( long double );
     
    83098445long double _Complex acosh( long double _Complex );
    83108446
    8311 float atanh( float );$\indexc{atanh}$
     8447float atanh( float );§\indexc{atanh}§
    83128448double atanh( double );
    83138449long double atanh( long double );
     
    83228458\leavevmode
    83238459\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8324 float erf( float );$\indexc{erf}$
     8460float erf( float );§\indexc{erf}§
    83258461double erf( double );
    83268462long double erf( long double );
     
    83298465long double _Complex erf( long double _Complex );
    83308466
    8331 float erfc( float );$\indexc{erfc}$
     8467float erfc( float );§\indexc{erfc}§
    83328468double erfc( double );
    83338469long double erfc( long double );
     
    83368472long double _Complex erfc( long double _Complex );
    83378473
    8338 float lgamma( float );$\indexc{lgamma}$
     8474float lgamma( float );§\indexc{lgamma}§
    83398475double lgamma( double );
    83408476long double lgamma( long double );
     
    83438479long double lgamma( long double, int * );
    83448480
    8345 float tgamma( float );$\indexc{tgamma}$
     8481float tgamma( float );§\indexc{tgamma}§
    83468482double tgamma( double );
    83478483long double tgamma( long double );
     
    83898525unsigned long long int ceiling( unsigned long long int n, unsigned long long int align );
    83908526
    8391 float floor( float );$\indexc{floor}$
     8527float floor( float );§\indexc{floor}§
    83928528double floor( double );
    83938529long double floor( long double );
    83948530
    8395 float ceil( float );$\indexc{ceil}$
     8531float ceil( float );§\indexc{ceil}§
    83968532double ceil( double );
    83978533long double ceil( long double );
    83988534
    8399 float trunc( float );$\indexc{trunc}$
     8535float trunc( float );§\indexc{trunc}§
    84008536double trunc( double );
    84018537long double trunc( long double );
    84028538
    8403 float rint( float );$\indexc{rint}$
     8539float rint( float );§\indexc{rint}§
    84048540long double rint( long double );
    84058541long int rint( float );
     
    84108546long long int rint( long double );
    84118547
    8412 long int lrint( float );$\indexc{lrint}$
     8548long int lrint( float );§\indexc{lrint}§
    84138549long int lrint( double );
    84148550long int lrint( long double );
     
    84178553long long int llrint( long double );
    84188554
    8419 float nearbyint( float );$\indexc{nearbyint}$
     8555float nearbyint( float );§\indexc{nearbyint}§
    84208556double nearbyint( double );
    84218557long double nearbyint( long double );
    84228558
    8423 float round( float );$\indexc{round}$
     8559float round( float );§\indexc{round}§
    84248560long double round( long double );
    84258561long int round( float );
     
    84308566long long int round( long double );
    84318567
    8432 long int lround( float );$\indexc{lround}$
     8568long int lround( float );§\indexc{lround}§
    84338569long int lround( double );
    84348570long int lround( long double );
     
    84438579\leavevmode
    84448580\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    8445 float copysign( float, float );$\indexc{copysign}$
     8581float copysign( float, float );§\indexc{copysign}§
    84468582double copysign( double, double );
    84478583long double copysign( long double, long double );
    84488584
    8449 float frexp( float, int * );$\indexc{frexp}$
     8585float frexp( float, int * );§\indexc{frexp}§
    84508586double frexp( double, int * );
    84518587long double frexp( long double, int * );
    84528588
    8453 float ldexp( float, int );$\indexc{ldexp}$
     8589float ldexp( float, int );§\indexc{ldexp}§
    84548590double ldexp( double, int );
    84558591long double ldexp( long double, int );
    84568592
    8457 [ float, float ] modf( float );$\indexc{modf}$
     8593[ float, float ] modf( float );§\indexc{modf}§
    84588594float modf( float, float * );
    84598595[ double, double ] modf( double );
     
    84628598long double modf( long double, long double * );
    84638599
    8464 float nextafter( float, float );$\indexc{nextafter}$
     8600float nextafter( float, float );§\indexc{nextafter}§
    84658601double nextafter( double, double );
    84668602long double nextafter( long double, long double );
    84678603
    8468 float nexttoward( float, long double );$\indexc{nexttoward}$
     8604float nexttoward( float, long double );§\indexc{nexttoward}§
    84698605double nexttoward( double, long double );
    84708606long double nexttoward( long double, long double );
    84718607
    8472 float scalbn( float, int );$\indexc{scalbn}$
     8608float scalbn( float, int );§\indexc{scalbn}§
    84738609double scalbn( double, int );
    84748610long double scalbn( long double, int );
    84758611
    8476 float scalbln( float, long int );$\indexc{scalbln}$
     8612float scalbln( float, long int );§\indexc{scalbln}§
    84778613double scalbln( double, long int );
    84788614long double scalbln( long double, long int );
     
    87348870All \newterm{pseudo random-number generators} (\newterm{PRNG}) involve some technique to scramble bits of a value, \eg multiplicative recurrence:
    87358871\begin{cfa}
    8736 rand = 36973 * (rand & 65535) + (rand >> 16); // scramble bits
     8872rand = 33967 * (rand + 1063); // scramble bits
    87378873\end{cfa}
    87388874Multiplication of large values adds new least-significant bits and drops most-significant bits.
     
    87418877bits 63--32 (most)      & bits 31--0 (least)    \\
    87428878\hline
    8743 0x0                                     & 0x3e8e36                              \\
    8744 0x5f                            & 0x718c25e1                    \\
    8745 0xad3e                          & 0x7b5f1dbe                    \\
    8746 0xbc3b                          & 0xac69ff19                    \\
    8747 0x1070f                         & 0x2d258dc6                    \\
     8879©0x0©                           & ©0x3e8e36©                    \\
     8880©0x5f©                          & ©0x718c25e1©                  \\
     8881©0xad3e©                        & ©0x7b5f1dbe©                  \\
     8882©0xbc3b©                        & ©0xac69ff19©                  \\
     8883©0x1070f©                       & ©0x2d258dc6©
    87488884\end{tabular}
    87498885\end{quote}
     
    87518887The least-significant bits \emph{appear} random but the same bits are always generated given a fixed starting value, called the \newterm{seed} (value 0x3e8e36 above).
    87528888Hence, if a program uses the same seed, the same sequence of pseudo-random values is generated from the PRNG.
    8753 Often the seed is set to another random value like a program's process identifier (©getpid©\index{getpid@©getpid©}) or time when the program is run;
     8889Often the seed is set to another random value like a program's process identifier (\Indexc{getpid}) or time when the program is run;
    87548890hence, one random value bootstraps another.
    87558891Finally, a PRNG usually generates a range of large values, \eg ©[0, UINT_MAX]©, which are scaled using the modulus operator, \eg ©prng() % 5© produces random values in the range 0--4.
    87568892
    8757 \CFA provides a sequential PRNG type only accessible by a single thread (not thread-safe) and a set of global and companion thread PRNG functions accessible by multiple threads without contention.
     8893\CFA provides 32/64-bit sequential PRNG type only accessible by a single thread (not thread-safe) and a set of global routines and companion thread PRNG functions accessible by multiple threads without contention.
     8894To use the PRNG interface \Textbf{requires including \Indexc{stdlib.hfa}}.
    87588895\begin{itemize}
    87598896\item
    8760 The ©PRNG© type is for sequential programs, like coroutining:
    8761 \begin{cfa}
    8762 struct PRNG { ... }; $\C[3.75in]{// opaque type}$
    8763 void ?{}( PRNG & prng ); §\C{// random seed}§
    8764 void ?{}( PRNG & prng, uint32_t seed ); §\C{// fixed seed}§
    8765 void set_seed( PRNG & prng, uint32_t seed ); §\C{// set seed}§
    8766 uint32_t get_seed( PRNG & prng ); §\C{// get seed}§
    8767 uint32_t prng( PRNG & prng ); §\C{// [0,UINT\_MAX]}§
    8768 uint32_t prng( PRNG & prng, uint32_t u ); §\C{// [0,u)}§
    8769 uint32_t prng( PRNG & prng, uint32_t l, uint32_t u ); §\C{// [l,u]}§
    8770 uint32_t calls( PRNG & prng ); §\C{// number of calls}\CRT§
    8771 \end{cfa}
     8897The ©PRNG© types for sequential programs, including coroutining, are:
     8898\begin{cfa}
     8899struct PRNG32 {};                                               §\C{// opaque type, no copy or assignment}§
     8900void ?{}( PRNG32 & prng, uint32_t seed ); §\C{// fixed seed}§
     8901void ?{}( PRNG32 & prng );                              §\C{// random seed}§
     8902void set_seed( PRNG32 & prng, uint32_t seed ); §\C{// set seed}§
     8903uint32_t get_seed( PRNG32 & prng );             §\C{// get seed}§
     8904uint32_t prng( PRNG32 & prng );                 §\C{// [0,UINT\_MAX]}§
     8905uint32_t prng( PRNG32 & prng, uint32_t u ); §\C{// [0,u)}§
     8906uint32_t prng( PRNG32 & prng, uint32_t l, uint32_t u ); §\C{// [l,u]}§
     8907uint32_t calls( PRNG32 & prng );                §\C{// number of calls}§
     8908void copy( PRNG32 & dst, PRNG32 & src ); §\C{// checkpoint PRNG state}§
     8909\end{cfa}
     8910\begin{cfa}
     8911struct PRNG64 {};                                               §\C{// opaque type, no copy or assignment}§
     8912void ?{}( PRNG64 & prng, uint64_t seed ); §\C{// fixed seed}§
     8913void ?{}( PRNG64 & prng );                              §\C{// random seed}§
     8914void set_seed( PRNG64 & prng, uint64_t seed ); §\C{// set seed}§
     8915uint64_t get_seed( PRNG64 & prng );             §\C{// get seed}§
     8916uint64_t prng( PRNG64 & prng );                 §\C{// [0,UINT\_MAX]}§
     8917uint64_t prng( PRNG64 & prng, uint64_t u ); §\C{// [0,u)}§
     8918uint64_t prng( PRNG64 & prng, uint64_t l, uint64_t u ); §\C{// [l,u]}§
     8919uint64_t calls( PRNG64 & prng );                §\C{// number of calls}§
     8920void copy( PRNG64 & dst, PRNG64 & src ); §\C{// checkpoint PRNG state}§
     8921\end{cfa}
     8922The type ©PRNG© is aliased to ©PRNG64© on 64-bit architectures and ©PRNG32© on 32-bit architectures.
    87728923A ©PRNG© object is used to randomize behaviour or values during execution, \eg in games, a character makes a random move or an object takes on a random value.
    87738924In this scenario, it is useful to have multiple ©PRNG© objects, \eg one per player or object.
    8774 However, sequential execution is still repeatable given the same starting seeds for all ©PRNG©s. 
     8925However, sequential execution is still repeatable given the same starting seeds for all ©PRNG©s.
    87758926\VRef[Figure]{f:SequentialPRNG} shows an example that creates two sequential ©PRNG©s, sets both to the same seed (1009), and illustrates the three forms for generating random values, where both ©PRNG©s generate the same sequence of values.
     8927Note, to prevent accidental PRNG copying, the copy constructor and assignment are hidden.
     8928To copy a PRNG for checkpointing, use the explicit ©copy© member.
    87768929
    87778930\begin{figure}
    87788931\begin{cfa}
    8779 PRNG prng1, prng2;
    8780 ®set_seed( prng1, 1009 )®;   ®set_seed( prng2, 1009 )®;
     8932PRNG sprng1, sprng2;                                    §\C{// select appropriate 32/64-bit PRNG}§
     8933®set_seed( sprng1, 1009 )®;   ®set_seed( sprng2, 1009 )®;
    87818934for ( 10 ) {
    87828935        // Do not cascade prng calls because side-effect functions called in arbitrary order.
    8783         sout | nlOff | ®prng( prng1 )®;  sout | ®prng( prng1, 5 )®;  sout | ®prng( prng1, 0, 5 )® | '\t';
    8784         sout | ®prng( prng2 )®;  sout | ®prng( prng2, 5 )®;  sout | ®prng( prng2, 0, 5 )® | nlOn;
     8936        sout | nlOff | ®prng( sprng1 )®;  sout | ®prng( sprng1, 5 )®;  sout | ®prng( sprng1, 0, 5 )® | '\t';
     8937        sout | ®prng( sprng2 )®;  sout | ®prng( sprng2, 5 )®;  sout | ®prng( sprng2, 0, 5 )® | nlOn;
    87858938}
    87868939\end{cfa}
     
    88218974The PRNG global and companion thread functions are for concurrent programming, such as randomizing execution in short-running programs, \eg ©yield( prng() % 5 )©.
    88228975\begin{cfa}
    8823 void set_seed( uint32_t seed ); $\C[3.75in]{// set global seed}$
    8824 uint32_t get_seed(); §\C{// get global seed}§
    8825 // SLOWER
    8826 uint32_t prng(); §\C{// [0,UINT\_MAX]}§
    8827 uint32_t prng( uint32_t u ); §\C{// [0,u)}§
    8828 uint32_t prng( uint32_t l, uint32_t u ); §\C{// [l,u]}§
    8829 // FASTER
    8830 uint32_t prng( $thread\LstStringStyle{\textdollar}$ & th );     §\C{// [0,UINT\_MAX]}§
    8831 uint32_t prng( $thread\LstStringStyle{\textdollar}$ & th, uint32_t u ); §\C{// [0,u)}§
    8832 uint32_t prng( $thread\LstStringStyle{\textdollar}$ & th, uint32_t l, uint32_t u );     §\C{// [l,u]}\CRT§
     8976void set_seed( size_t seed );                   §\C{// set global seed}§
     8977size_t get_seed();                                              §\C{// get global seed}§
     8978// SLOWER, global routines
     8979size_t prng( void );                                    §\C{// [0,UINT\_MAX]}§
     8980size_t prng( size_t u );                                §\C{// [0,u)}§
     8981size_t prng( size_t l, size_t u );              §\C{// [l,u]}§
     8982// FASTER, thread members
     8983size_t prng( §thread\LstStringStyle{\textdollar}§ & th );       §\C{// [0,UINT\_MAX]}§
     8984size_t prng( §thread\LstStringStyle{\textdollar}§ & th, size_t u );     §\C{// [0,u)}§
     8985size_t prng( §thread\LstStringStyle{\textdollar}§ & th, size_t l, size_t u );   §\C{// [l,u]}§
    88338986\end{cfa}
    88348987The only difference between the two sets of ©prng© routines is performance.
     
    88418994Hence, these threads generate different sequences of random numbers.
    88428995If each thread needs its own seed, use a sequential ©PRNG© in each thread.
    8843 The slower ©prng© functions \emph{without} a thread argument call ©active_thread© internally to indirectly access the current thread's PRNG state, while the faster ©prng© functions \emph{with} a thread argument directly access the thread through the thread parameter.
     8996The slower ©prng© global functions, \ie \emph{without} a thread argument, call ©active_thread© internally to indirectly access the current thread's PRNG state, while the faster ©prng© functions, \ie \emph{with} a thread argument, directly access the thread through the thread parameter.
    88448997If a thread pointer is available, \eg in thread main, eliminating the call to ©active_thread© significantly reduces the cost of accessing the thread's PRNG state.
    88458998\VRef[Figure]{f:ConcurrentPRNG} shows an example using the slower/faster concurrent PRNG in the program main and a thread.
     
    88569009int main() {
    88579010        set_seed( 1009 );
    8858         $\R{thread\LstStringStyle{\textdollar}}$ ®& th = *active_thread()®;  // program-main thread-address
     9011        §\R{thread\LstStringStyle{\textdollar}}§ ®& th = *active_thread()®;  // program-main thread-address
    88599012        for ( i; 10 ) {
    88609013                sout | nlOff | ®prng()®; sout | ®prng( 5 )®; sout | ®prng( 0, 5 )® | '\t';  // SLOWER
     
    90799232\hline
    90809233\begin{cfa}
    9081 #include <gmp.h>$\indexc{gmp.h}$
     9234#include <gmp.h>§\indexc{gmp.h}§
    90829235int main( void ) {
    90839236        ®gmp_printf®( "Factorial Numbers\n" );
     
    90939246&
    90949247\begin{cfa}
    9095 #include <gmp.hfa>$\indexc{gmp}$
     9248#include <gmp.hfa>§\indexc{gmp}§
    90969249int main( void ) {
    90979250        sout | "Factorial Numbers";
     
    91659318\begin{cfa}[belowskip=0pt]
    91669319// implementation
    9167 struct Rational {$\indexc{Rational}$
     9320struct Rational {§\indexc{Rational}§
    91689321        long int numerator, denominator; §\C{// invariant: denominator > 0}§
    91699322}; // Rational
  • libcfa/src/collections/string_res.cfa

    rc75b30a r32490deb  
    1010// Created On       : Fri Sep 03 11:00:00 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 16 22:19:27 2024
    13 // Update Count     : 35
     12// Last Modified On : Mon Jan 22 23:12:42 2024
     13// Update Count     : 43
    1414//
    1515
     
    263263        bool cont = false;
    264264
    265         _Istream_Cstr cf = { cstr, (_Istream_str_base)f };
     265        _Istream_Cwidth cf = { cstr, (_Istream_str_base)f };
    266266        if ( ! cf.flags.rwd ) cf.wd = wd;
    267267
  • libcfa/src/fstream.cfa

    rc75b30a r32490deb  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Nov 15 10:51:14 2023
    13 // Update Count     : 552
     12// Last Modified On : Sun Jan 28 09:56:08 2024
     13// Update Count     : 554
    1414//
    1515
     
    209209void ?{}( ifstream & is, void * file ) with( is ) {
    210210        file$ = file;
    211         nlOnOff$ = false;
     211        nlOnOff$ = false;                                                                       // => skip newlines when reading single characters
    212212} // ?{}
    213213
  • libcfa/src/iostream.cfa

    rc75b30a r32490deb  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan  3 10:53:13 2024
    13 // Update Count     : 1898
     12// Last Modified On : Sun Jan 28 11:58:54 2024
     13// Update Count     : 1917
    1414//
    1515
     
    944944        istype & nl( istype & is ) {
    945945                fmt( is, "%*[^\n]" );                                                   // ignore characters to newline
    946                 if ( ! eof( is ) && getANL$( is ) ) fmt( is, "%*c" ); // read newline
     946                if ( ! eof( is ) ) fmt( is, "%*c" );                    // read newline
    947947                return is;
    948948        } // nl
     
    984984        }
    985985
    986         istype & ?|?( istype & is, _Istream_Cquoted f ) with( f ) {
    987                 char fmtstr[32];                                                                // storage scanset and format codes
     986        istype & ?|?( istype & is, _Istream_Cquoted f ) with( f.cstr ) {
     987                int args;
     988          fini: {
     989                        args = fmt( is, "%*[ \f\n\r\t\v]" );            // remove leading whitespace
     990                        if ( eof( is ) ) break fini;
     991                        char rfmt[4] = { delimiters[0], '%', 'n', '\0' };
     992                        int len = 0;                                                            // may not be set in fmt
     993                        args = fmt( is, rfmt, &len );                           // remove leading quote
     994                        if ( len == 0 || eof( is ) ) break fini;
     995
     996                        // Change the remainder of the read into a getline by reseting the closing delimiter.
     997                        if ( delimiters[1] != '\0' ) {
     998                                delimiters[0] = delimiters[1];
     999                                delimiters[1] = '\0';
     1000                        } // if
     1001                        flags.delimiter = true;
     1002                        return is | *(_Istream_Cstr *)&f;
     1003                } // fini
     1004                // read failed => no pattern match => set string to null
     1005                if ( ! flags.ignore && s != 0p && args == 0 ) s[0] = '\0';
     1006                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
     1007                        clear( is );                                                            // => reset EOF => detect again on next read
     1008                } // if
     1009                return is;
     1010        }
     1011
     1012        istype & ?|?( istype & is, _Istream_Cstr f ) with( f.cstr ) {
     1013                const char * scanset;
     1014                size_t nscanset = 0;
     1015                if ( flags.delimiter ) scanset = delimiters;    // getline ?
     1016                else scanset = f.cstr.scanset;
     1017                if ( scanset ) nscanset = strlen( scanset );
     1018
     1019                char fmtstr[nscanset + 32];                                             // storage for scanset and format codes
    9881020                fmtstr[0] = '%';
    989 
    9901021                int pos = 1;
    9911022                int args;
    9921023                bool check = true;
    9931024
    994                 if ( cstr.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
    995                 int rwd = cstr.wd;
    996                 if ( cstr.wd != -1 ) {                                          // => just ignore versus ignore with width
     1025                if ( flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
     1026                int rwd = wd;
     1027                if ( wd != -1 ) {                                                               // => just ignore versus ignore with width
    9971028                        // wd is buffer bytes available (for input chars + null terminator)
    9981029                        // rwd is count of input chars
    9991030                        // no maximum width necessary because text ignored => width is read width
    1000                         if ( cstr.flags.rwd ) check = false;
    1001                         else rwd = cstr.wd - 1;
     1031                        if ( flags.rwd ) check = false;
     1032                        else rwd = wd - 1;
     1033                        assert( rwd > 0 );
    10021034                        pos += sprintf( &fmtstr[pos], "%d", rwd );
    10031035                } // if
    10041036
    1005                 int len = 0;                                                                    // may not be set in fmt
    1006                 char enddelim;
    1007                 if ( ! cstr.flags.inex ) {                                              // => quoted getline
    1008                         args = fmt( is, "%*[ \f\n\r\t\v]" );            // remove leading whitespace
    1009                         if ( eof( is ) ) goto Eof;
    1010                         char rfmt[4] = { cstr.delimiters[0], '%', 'n', '\0' };
    1011                         args = fmt( is, rfmt, &len );                           // remove leading quote
    1012                         if ( len == 0 || eof( is ) ) goto Eof;
    1013                 } // if
    1014                 enddelim = cstr.delimiters[1] == '\0' ? cstr.delimiters[0] : cstr.delimiters[1];
    1015                 sprintf( &fmtstr[pos], "[^%c]%%n", enddelim );
    1016                 if ( cstr.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    1017                 else args = fmt( is, fmtstr, cstr.s, &len );
    1018                 if ( check && len == rwd && ! eof( is ) ) {             // might not fit
    1019                         char peek;
    1020                         fmt( is, "%c", &peek );                                         // check for delimiter
    1021                         if ( ! eof( is ) ) {
    1022                                 if ( peek != enddelim ) {
    1023                                         ungetc( is, peek );
    1024                                         throwResume ExceptionInst( cstring_length );
    1025                                 } // if
    1026                         } // if
    1027                 } else fmt( is, "%*c" );                                                // remove delimiter
    1028           Eof: ;
    1029                 if ( rwd > 0 && args == 0 ) cstr.s[0] = '\0';   // read failed => no pattern match => set string to null
    1030                 if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
    1031                         clear( is );                                                            // => reset EOF => detect again on next read
    1032                 } // if
    1033                 return is;
    1034         }
    1035 
    1036         istype & ?|?( istype & is, _Istream_Cstr f ) with( f ) {
    1037                 const char * scanset;
    1038                 size_t nscanset = 0;
    1039                 if ( flags.delimiter ) scanset = delimiters;    // getline ?
    1040                 else scanset = f.scanset;
    1041                 if ( scanset ) nscanset = strlen( scanset );
    1042 
    1043                 char fmtstr[nscanset + 32];                                             // storage for scanset and format codes
    1044                 fmtstr[0] = '%';
    1045 
    1046                 int pos = 1;
    1047                 int args;
    1048                 bool check = true;
    1049 
    1050                 if ( f.flags.ignore ) { check = false; fmtstr[1] = '*'; pos += 1; }
    1051                 int rwd = f.wd;
    1052                 if ( f.wd != -1 ) {                                                             // => just ignore versus ignore with width
    1053                         // wd is buffer bytes available (for input chars + null terminator)
    1054                         // rwd is count of input chars
    1055                         // no maximum width necessary because text ignored => width is read width
    1056                         if ( f.flags.rwd ) check = false;
    1057                         else rwd = f.wd - 1;
    1058                         pos += sprintf( &fmtstr[pos], "%d", rwd );
    1059                 } // if
    1060 
    10611037                if ( ! scanset ) {                                                              // %s, %*s, %ws, %*ws
    1062                         // fprintf( stderr, "cstr %s\n", f.s );
     1038                        // fprintf( stderr, "cstr %s\n", s );
    10631039                        strcpy( &fmtstr[pos], "s%n" );
    10641040                        int len = 0;                                                            // may not be set in fmt
    1065                         if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    1066                         else args = fmt( is, fmtstr, f.s, &len );
    1067                         // fprintf( stderr, "cstr %s %d %d %d %s\n", fmtstr, args, len, f.wd, f.s );
     1041                        if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1042                        else args = fmt( is, fmtstr, s, &len );
     1043                        // fprintf( stderr, "cstr %s %d %d %d %s\n", fmtstr, args, len, wd, s );
    10681044                        if ( check && len >= rwd && ! eof( is ) ) {     // might not fit
    10691045                                char peek;
     
    10761052                        } // if
    10771053                        // FIX ME: CFA strings need to be modified to NOT change the argument for this case, then this can be removed.
    1078                         if ( rwd > 0 && args == 0 ) f.s[0]= '\0';       // read failed => no pattern match => set string to null
     1054                        if ( ! flags.ignore && args == 0 ) s[0]= '\0'; // read failed => no pattern match => set string to null
    10791055                } else {
    1080                         if ( f.flags.delimiter ) {                                      // getline
     1056                        if ( flags.delimiter ) {                                        // getline
    10811057                                int len = 0;                                                    // may not be set in fmt
    1082                                 sprintf( &fmtstr[pos], "[^%c]%%n", f.delimiters[0] );
    1083                                 if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    1084                                 else args = fmt( is, fmtstr, f.s, &len );
     1058                                if ( delimiters[2] != '\0' ) {                  // read single character ?
     1059                                        sprintf( &fmtstr[pos], "c%%n" );
     1060                                } else {
     1061                                        sprintf( &fmtstr[pos], "[^%c]%%n", delimiters[0] );
     1062                                } // if
     1063                                if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1064                                else args = fmt( is, fmtstr, s, &len );
    10851065                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
    1086                                         fmtstr[0] = f.delimiters[0]; fmtstr[1] = '%'; fmtstr[2] = 'n'; fmtstr[3] = '\0';
    1087                                         fmt( is, fmtstr, &len );                        // remove delimiter
     1066                                        char peek;
     1067                                        fmt( is, "%c", &peek );                         // check for delimiter
    10881068                                        if ( ! eof( is ) ) {
    1089 //                                              if ( peek != f.delimiter[0] ) {
    1090                                                 if ( len != 1 ) {
    1091 //                                                      ungetc( is, peek );
     1069                                                if ( peek != delimiters[0] ) {
     1070                                                        ungetc( is, peek );
    10921071                                                        throwResume ExceptionInst( cstring_length );
    10931072                                                } // if
     
    10971076                                // incl %[xxx],  %*[xxx],  %w[xxx],  %*w[xxx]
    10981077                                // excl %[^xxx], %*[^xxx], %w[^xxx], %*w[^xxx]
    1099                                 sprintf( &fmtstr[pos], "[%s%s]%%n", f.flags.inex ? "^" : "", scanset );
    1100                                 // fprintf( stderr, "incl/excl %s %d\n", fmtstr, f.wd );
     1078                                sprintf( &fmtstr[pos], "[%s%s]%%n", flags.inex ? "^" : "", scanset );
     1079                                // fprintf( stderr, "incl/excl %s %d\n", fmtstr, wd );
    11011080                                int len = 0;                                                    // may not be set in fmt
    1102                                 if ( f.flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
    1103                                 else args = fmt( is, fmtstr, f.s, &len );
    1104                                 // fprintf( stderr, "incl/excl %s \"%s\" %d %d %d %d %d %c\n", fmtstr, f.s, args, f.wd, len, eof( is ), check, f.s[f.wd] );
     1081                                if ( flags.ignore ) args = fmt( is, fmtstr, &len ); // no string argument for '*'
     1082                                else args = fmt( is, fmtstr, s, &len );
     1083                                // fprintf( stderr, "incl/excl %s \"%s\" %d %d %d %d %d %c\n", fmtstr, s, args, wd, len, eof( is ), check, s[wd] );
    11051084                                if ( check && len == rwd && ! eof( is ) ) {     // might not fit
    11061085                                        // fprintf( stderr, "overflow\n" );
     
    11101089                                        if ( ! eof( is ) ) {
    11111090                                                ungetc( is, peek );
    1112                                                 if ( f.flags.inex ^ strchr( f.scanset, peek ) != 0p ) throwResume ExceptionInst( cstring_length );
     1091                                                if ( flags.inex ^ strchr( scanset, peek ) != 0p ) throwResume ExceptionInst( cstring_length );
    11131092                                        } // if
    11141093                                } // if
    11151094                        } // if
    1116                         if ( rwd > 0 && args == 0 ) f.s[0]= '\0';       // read failed => no pattern match => set string to null
     1095                        if ( ! flags.ignore && args == 0 ) s[0]= '\0'; // read failed => no pattern match => set string to null
    11171096                } // if
    11181097                if ( args == 1 && eof( is ) ) {                                 // data but scan ended at EOF
     
    11201099                        clear( is );                                                            // => reset EOF => detect again on next read
    11211100                } // if
    1122                 return is;
    1123         } // ?|?
    1124 
    1125         istype & ?|?( istype & is, _Istream_Char f ) {
    1126                 fmt( is, "%*c" );                                                               // argument variable unused
    11271101                return is;
    11281102        } // ?|?
     
    11451119} // distribution
    11461120
     1121INPUT_FMT_IMPL( char, "c" )
    11471122INPUT_FMT_IMPL( signed char, "hhi" )
    11481123INPUT_FMT_IMPL( unsigned char, "hhi" )
  • libcfa/src/iostream.hfa

    rc75b30a r32490deb  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jan  3 10:53:18 2024
    13 // Update Count     : 610
     12// Last Modified On : Sun Jan 28 11:56:29 2024
     13// Update Count     : 733
    1414//
    1515
     
    196196// *********************************** integral ***********************************
    197197
    198 // See 6.7.9. 19) The initialization shall occur in initializer list order, each initializer provided for a particular
    199 // subobject overriding any previously listed initializer for the same subobject; ***all subobjects that are not
    200 // initialized explicitly shall be initialized implicitly the same as objects that have static storage duration.***
    201 
    202198#define INTEGRAL_FMT_DECL( T, CODE ) \
    203199static inline { \
    204         _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'b', { .all : 0 } }; } \
    205         _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'o', { .all : 0 } }; } \
    206         _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'x', { .all : 0 } }; } \
    207         _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, CODE, { .all : 0 } }; } \
    208         _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, CODE, { .flags.pc : true } }; } \
    209         _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { fmt.wd = w; return fmt; } \
    210         _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     200        _Ostream_Manip(T) bin( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'b', { .all : 0 } }; } \
     201        _Ostream_Manip(T) oct( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'o', { .all : 0 } }; } \
     202        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'x', { .all : 0 } }; } \
     203        _Ostream_Manip(T) wd( unsigned int wd, T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : wd, .pc : 0, .base : CODE, { .all : 0 } }; } \
     204        _Ostream_Manip(T) wd( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : wd, .pc : pc, .base : CODE, { .flags.pc : true } }; } \
     205        _Ostream_Manip(T) & wd( unsigned int wd, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \
     206        _Ostream_Manip(T) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    211207        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    212208        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; } \
    213209        _Ostream_Manip(T) & nobase( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    214210        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
    215         _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, CODE, { .flags.sign : true } }; } \
     211        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : CODE, { .flags.sign : true } }; } \
    216212        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    217213} /* distribution */ \
     
    241237#define FLOATING_POINT_FMT_DECL( T ) \
    242238static inline { \
    243         _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'a', { .all : 0 } }; } \
    244         _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'e', { .all : 0 } }; } \
    245         _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ val, 1, -1, 'g', { .flags.eng : true } }; } \
    246         _Ostream_Manip(T) wd( unsigned int w, T val ) { return (_Ostream_Manip(T))@{ val, w, 0, 'g', { .all : 0 } }; } \
    247         _Ostream_Manip(T) wd( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'f', { .flags.pc : true } }; } \
    248         _Ostream_Manip(T) ws( unsigned int w, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ val, w, pc, 'g', { .flags.pc : true } }; } \
    249         _Ostream_Manip(T) & wd( unsigned int w, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; return fmt; } \
    250         _Ostream_Manip(T) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    251         _Ostream_Manip(T) & ws( unsigned int w, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     239        _Ostream_Manip(T) hex( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'a', { .all : 0 } }; } \
     240        _Ostream_Manip(T) sci( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'e', { .all : 0 } }; } \
     241        _Ostream_Manip(T) eng( T val ) { return (_Ostream_Manip(T))@{ .val : val, 1, -1, .base : 'g', { .flags.eng : true } }; } \
     242        _Ostream_Manip(T) wd( unsigned int wd, T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : wd, .pc : 0, .base : 'g', { .all : 0 } }; } \
     243        _Ostream_Manip(T) wd( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : wd, .pc : pc, .base : 'f', { .flags.pc : true } }; } \
     244        _Ostream_Manip(T) ws( unsigned int wd, unsigned int pc, T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : wd, .pc : pc, .base : 'g', { .flags.pc : true } }; } \
     245        _Ostream_Manip(T) & wd( unsigned int wd, _Ostream_Manip(T) & fmt ) { if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = wd; return fmt; } \
     246        _Ostream_Manip(T) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { \
     247                if ( fmt.flags.eng ) fmt.base = 'f'; fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
     248        _Ostream_Manip(T) & ws( unsigned int wd, unsigned int pc, _Ostream_Manip(T) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; } \
    252249        _Ostream_Manip(T) & left( _Ostream_Manip(T) & fmt ) { fmt.flags.left = true; return fmt; } \
    253         _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'G', { .all : 0 } }; } \
     250        _Ostream_Manip(T) upcase( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'G', { .all : 0 } }; } \
    254251        _Ostream_Manip(T) & upcase( _Ostream_Manip(T) & fmt ) { fmt.base -= 32; /* upper case */ return fmt; } \
    255252        _Ostream_Manip(T) & pad0( _Ostream_Manip(T) & fmt ) { fmt.flags.pad0 = true; return fmt; } \
    256         _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.sign : true } }; } \
     253        _Ostream_Manip(T) sign( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'g', { .flags.sign : true } }; } \
    257254        _Ostream_Manip(T) & sign( _Ostream_Manip(T) & fmt ) { fmt.flags.sign = true; return fmt; } \
    258         _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
     255        _Ostream_Manip(T) nodp( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'g', { .flags.nobsdp : true } }; } \
    259256        _Ostream_Manip(T) & nodp( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    260         _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ val, 1, 0, 'g', { .flags.nobsdp : true } }; } \
     257        _Ostream_Manip(T) unit( T val ) { return (_Ostream_Manip(T))@{ .val : val, .wd : 1, .pc : 0, .base : 'g', { .flags.nobsdp : true } }; } \
    261258        _Ostream_Manip(T) & unit( _Ostream_Manip(T) & fmt ) { fmt.flags.nobsdp = true; return fmt; } \
    262259} /* distribution */ \
     
    272269
    273270static inline {
    274         _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'b', { .all : 0 } }; }
    275         _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'o', { .all : 0 } }; }
    276         _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ c, 1, 0, 'x', { .all : 0 } }; }
    277         _Ostream_Manip(char) wd( unsigned int w, char c ) { return (_Ostream_Manip(char))@{ c, w, 0, 'c', { .all : 0 } }; }
    278         _Ostream_Manip(char) & wd( unsigned int w, _Ostream_Manip(char) & fmt ) { fmt.wd = w; return fmt; }
     271        _Ostream_Manip(char) bin( char c ) { return (_Ostream_Manip(char))@{ .val : c, .wd : 1, .pc : 0, .base : 'b', { .all : 0 } }; }
     272        _Ostream_Manip(char) oct( char c ) { return (_Ostream_Manip(char))@{ .val : c, .wd : 1, .pc : 0, .base : 'o', { .all : 0 } }; }
     273        _Ostream_Manip(char) hex( char c ) { return (_Ostream_Manip(char))@{ .val : c, .wd : 1, .pc : 0, .base : 'x', { .all : 0 } }; }
     274        _Ostream_Manip(char) wd( unsigned int wd, char c ) { return (_Ostream_Manip(char))@{ c, wd, 0, .base : 'c', { .all : 0 } }; }
     275        _Ostream_Manip(char) & wd( unsigned int wd, _Ostream_Manip(char) & fmt ) { fmt.wd = wd; return fmt; }
    279276        _Ostream_Manip(char) & left( _Ostream_Manip(char) & fmt ) { fmt.flags.left = true; return fmt; }
    280277        _Ostream_Manip(char) & upcase( _Ostream_Manip(char) & fmt ) { if ( fmt.base == 'x' || fmt.base == 'b' ) fmt.base -= 32; /* upper case */ return fmt; }
     
    289286
    290287static inline {
    291         _Ostream_Manip(const char *) bin( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'b', { .all : 0 } }; }
    292         _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'o', { .all : 0 } }; }
    293         _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ s, 1, 0, 'x', { .all : 0 } }; }
    294         _Ostream_Manip(const char *) wd( unsigned int w, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, 0, 's', { .all : 0 } }; }
    295         _Ostream_Manip(const char *) wd( unsigned int w, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, w, pc, 's', { .flags.pc : true } }; }
    296         _Ostream_Manip(const char *) & wd( unsigned int w, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; return fmt; }
    297         _Ostream_Manip(const char *) & wd( unsigned int w, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = w; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
     288        _Ostream_Manip(const char *) bin( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val : s, .wd : 1, .pc : 0, .base : 'b', { .all : 0 } }; }
     289        _Ostream_Manip(const char *) oct( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val : s, .wd : 1, .pc : 0, .base : 'o', { .all : 0 } }; }
     290        _Ostream_Manip(const char *) hex( const char s[] ) { return (_Ostream_Manip(const char *))@{ .val : s, .wd : 1, .pc : 0, .base : 'x', { .all : 0 } }; }
     291        _Ostream_Manip(const char *) wd( unsigned int wd, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, wd, 0, .base : 's', { .all : 0 } }; }
     292        _Ostream_Manip(const char *) wd( unsigned int wd, unsigned int pc, const char s[] ) { return (_Ostream_Manip(const char *))@{ s, .wd : wd, .pc : pc, .base : 's', { .flags.pc : true } }; }
     293        _Ostream_Manip(const char *) & wd( unsigned int wd, _Ostream_Manip(const char *) & fmt ) { fmt.wd = wd; return fmt; }
     294        _Ostream_Manip(const char *) & wd( unsigned int wd, unsigned int pc, _Ostream_Manip(const char *) & fmt ) { fmt.wd = wd; fmt.pc = pc; fmt.flags.pc = true; return fmt; }
    298295        _Ostream_Manip(const char *) & left( _Ostream_Manip(const char *) & fmt ) { fmt.flags.left = true; return fmt; }
    299296        _Ostream_Manip(const char *) & nobase( _Ostream_Manip(const char *) & fmt ) { fmt.flags.nobsdp = true; return fmt; }
     
    385382
    386383static inline {
    387         _Istream_Cskip skip( const char scanset[] ) { return (_Istream_Cskip)@{ scanset, 0 }; }
    388         _Istream_Cskip skip( unsigned int wd ) { return (_Istream_Cskip)@{ 0p, wd }; }
     384        _Istream_Cskip skip( const char scanset[] ) { return (_Istream_Cskip)@{ .scanset : scanset, .wd : 0 }; }
     385        _Istream_Cskip skip( unsigned int wd ) { return (_Istream_Cskip)@{ .scanset : 0p, .wd : wd }; }
    389386} // distribution
    390387
     
    400397                        unsigned char ignore:1;                                         // do not change input argument
    401398                        unsigned char inex:1;                                           // include/exclude characters in scanset
    402                         unsigned char delimiter:1;                                      // delimit character
     399                        unsigned char delimiter:1;                                      // delimit character(s)
    403400                        unsigned char rwd:1;                                            // read width
    404401                } flags;
     
    406403}; // _Istream_str_base
    407404
    408 struct _Istream_Cstr {
     405struct _Istream_Cwidth {
    409406        char * s;
    410407        inline _Istream_str_base;
    411408}; // _Istream_Cstr
    412409
     410// Restrict nesting of input manipulators to those combinations that make sense.
     411
     412struct _Istream_Cstr {
     413        _Istream_Cwidth cstr;
     414}; // _Istream_Cstr
     415
    413416struct _Istream_Cquoted {
    414         _Istream_Cstr cstr;
     417        _Istream_Cwidth cstr;
    415418}; // _Istream_Cquoted
    416419
    417420static inline {
    418         // width must include room for null terminator
    419         _Istream_Cstr wdi( unsigned int wd, char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, wd, {.all : 0} } }; }
    420         _Istream_Cstr wdi( unsigned int wd, unsigned int rwd, char s[] ) {
    421                 if ( wd <= rwd ) throw (cstring_length){ &cstring_length_vt };
    422                 return (_Istream_Cstr)@{ s, { {0p}, rwd, {.flags.rwd : true} } };
     421        // width must include room for null terminator, (gcc) scanf does not allow a 0 width => wd > 1 (1 char and null) and rd > 0 (1 char);
     422        _Istream_Cwidth wdi( unsigned int wd, char s[] ) {
     423                if ( wd <= 1 ) throw (cstring_length){ &cstring_length_vt }; // minimum 1 character and null terminator
     424                return (_Istream_Cwidth)@{ .s : s, { {.scanset : 0p}, .wd : wd, {.all : 0} } };
    423425        }
    424         _Istream_Cquoted & quoted( _Istream_Cstr & fmt, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) {
    425                 fmt.delimiters[0] = Ldelimiter;  fmt.delimiters[1] = Rdelimiter;  fmt.delimiters[2] = '\0';
    426                 return (_Istream_Cquoted &)fmt;
     426        _Istream_Cwidth wdi( unsigned int wd, unsigned int rwd, char s[] ) {
     427                if ( wd <= 1 || wd <= rwd ) throw (cstring_length){ &cstring_length_vt }; // minimum 1 character, null terminator, plus subset
     428                return (_Istream_Cwidth)@{ .s : s, { {.scanset : 0p}, .wd : rwd, {.flags.rwd : true} } };
    427429        }
    428         _Istream_Cstr & getline( _Istream_Cstr & fmt, const char delimiter = '\n' ) {
    429                 fmt.delimiters[0] = delimiter; fmt.delimiters[1] = '\0'; fmt.flags.delimiter = true; fmt.flags.inex = true; return fmt;
     430        _Istream_Cquoted quoted( char & ch, const char Ldelimiter = '\'', const char Rdelimiter = '\0' ) {
     431                return (_Istream_Cquoted)@{ { .s : &ch, { {.delimiters : { Ldelimiter, Rdelimiter, '\1' }}, .wd : 1, {.flags.rwd : true} } } };
    430432        }
    431         _Istream_Cstr & incl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = false; return fmt; }
    432         _Istream_Cstr & excl( const char scanset[], _Istream_Cstr & fmt ) { fmt.scanset = scanset; fmt.flags.inex = true; return fmt; }
    433         _Istream_Cstr ignore( char s[] ) { return (_Istream_Cstr)@{ s, { {0p}, -1, {.flags.ignore : true} } }; }
    434         _Istream_Cstr & ignore( _Istream_Cstr & fmt ) { fmt.flags.ignore = true; return fmt; }
     433        _Istream_Cquoted & quoted( _Istream_Cwidth & f, const char Ldelimiter = '"', const char Rdelimiter = '\0' ) {
     434                f.delimiters[0] = Ldelimiter;  f.delimiters[1] = Rdelimiter;  f.delimiters[2] = '\0';
     435                return (_Istream_Cquoted &)f;
     436        }
     437        _Istream_Cstr & getline( _Istream_Cwidth & f, const char delimiter = '\n' ) {
     438                f.delimiters[0] = delimiter; f.delimiters[1] = '\0'; f.flags.delimiter = true; return (_Istream_Cstr &)f;
     439        }
     440        _Istream_Cstr & incl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = false; return (_Istream_Cstr &)f; }
     441        _Istream_Cstr & excl( const char scanset[], _Istream_Cwidth & f ) { f.scanset = scanset; f.flags.inex = true; return (_Istream_Cstr &)f; }
     442        _Istream_Cstr ignore( const char s[] ) { return (_Istream_Cwidth)@{ .s : (char *)s, { {.scanset : 0p}, .wd : -1, {.flags.ignore : true} } }; }
     443        _Istream_Cstr & ignore( _Istream_Cwidth & f ) { f.flags.ignore = true; return (_Istream_Cstr &)f; }
     444        _Istream_Cquoted & ignore( _Istream_Cquoted & f ) { f.cstr.flags.ignore = true; return (_Istream_Cquoted &)f; }
     445        _Istream_Cstr & ignore( _Istream_Cstr & f ) { f.cstr.flags.ignore = true; return (_Istream_Cstr &)f; }
    435446} // distribution
    436447
    437448forall( istype & | basic_istream( istype ) ) {
    438         istype & ?|?( istype & is, _Istream_Cstr f );
    439449        istype & ?|?( istype & is, _Istream_Cskip f );
    440450        istype & ?|?( istype & is, _Istream_Cquoted f );
    441 } // distribution
    442 
    443 struct _Istream_Char {
    444         bool ignore;                                                                            // do not change input argument
    445 }; // _Istream_Char
    446 
    447 static inline {
    448         _Istream_Char ignore( const char ) { return (_Istream_Char)@{ true }; }
    449         _Istream_Char & ignore( _Istream_Char & fmt ) { fmt.ignore = true; return fmt; }
    450 } // distribution
    451 forall( istype & | basic_istream( istype ) ) {
    452         istype & ?|?( istype & is, _Istream_Char f );
    453 }
     451        istype & ?|?( istype & is, _Istream_Cstr f );
     452        static inline {
     453                istype & ?|?( istype & is, _Istream_Cwidth f ) { return is | *(_Istream_Cstr *)&f; }
     454        } // distribution
     455} // distribution
    454456
    455457forall( T & | sized( T ) )
     
    462464#define INPUT_FMT_DECL( T ) \
    463465static inline { \
    464         _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ (T &)val, -1, true }; } \
     466        _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ .val : val, .wd : wd, .ignore : false }; } \
     467        _Istream_Manip(T) ignore( const T & val ) { return (_Istream_Manip(T))@{ .val : (T &)val, .wd : -1, .ignore : true }; } \
    465468        _Istream_Manip(T) & ignore( _Istream_Manip(T) & fmt ) { fmt.ignore = true; return fmt; } \
    466         _Istream_Manip(T) wdi( unsigned int wd, T & val ) { return (_Istream_Manip(T))@{ val, wd, false }; } \
    467         _Istream_Manip(T) & wdi( unsigned int wd, _Istream_Manip(T) & fmt ) { fmt.wd = wd; return fmt; } \
    468469} /* distribution */ \
    469470forall( istype & | basic_istream( istype ) ) { \
     
    471472} // ?|?
    472473
     474INPUT_FMT_DECL( char )
    473475INPUT_FMT_DECL( signed char )
    474476INPUT_FMT_DECL( unsigned char )
  • src/Common/utility.h

    rc75b30a r32490deb  
    111111};
    112112
    113 // -----------------------------------------------------------------------------
    114 // O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most
    115 // significant bit (single instruction on x86)
    116 
    117 template<typename T>
    118 inline
    119 #if defined(__GNUC__) && __GNUC__ > 4
    120 constexpr
    121 #endif
    122 T ilog2(const T & t) {
    123         if(std::is_integral<T>::value) {
    124                 const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;
    125                 if( sizeof(T) == sizeof(unsigned       int) ) return r - __builtin_clz  ( t );
    126                 if( sizeof(T) == sizeof(unsigned      long) ) return r - __builtin_clzl ( t );
    127                 if( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );
    128         }
    129         assert(false);
    130         return -1;
    131 } // ilog2
    132 
    133113// Local Variables: //
    134114// tab-width: 4 //
  • src/ResolvExpr/Resolver.cc

    rc75b30a r32490deb  
    5050
    5151namespace ResolvExpr {
    52         template< typename iterator_t >
    53         inline bool advance_to_mutex( iterator_t & it, const iterator_t & end ) {
    54                 while( it != end && !(*it)->get_type()->get_mutex() ) {
    55                         it++;
    56                 }
    57 
    58                 return it != end;
    59         }
    60 
    6152        namespace {
    6253                /// Finds deleted expressions in an expression tree
  • tests/collections/.expect/string-istream-manip.txt

    rc75b30a r32490deb  
    686812 wwwwwwww
    696913 wwwwwwww
    70 14 cccc
     7014
    717115
    72721 yyyyyyyyyyyyyyyyyyyy
     
    838312 wwwwwwww
    848413 wwwwwwww
    85 14 cccc
     8514
    868615
  • tests/collections/.in/string-istream-manip.txt

    rc75b30a r32490deb  
    3636abcxxx
    3737abcyyy
    38 aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    39 uuuuuccccuuuuu
     38aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
     39uuuuu
    4040abc
    4141cccccb
     
    4343abcxxx
    4444abcyyy
    45 aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    46 uuuuuccccuuuuu
     45aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
     46uuuuu
  • tests/collections/string-istream-manip.cfa

    rc75b30a r32490deb  
    165165        sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    166166        sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
     167                sin | "\n";
    167168
    168169                s = "q";
     
    191192        sin | ignore( incl( "abc", wdi( 8, s ) ) );     sout | "12" | s;
    192193        sin | ignore( excl( "abc", wdi( 8, s ) ) );     sout | "13" | s;
     194                sin | "\n";
    193195
    194196                s = "q";
  • tests/io/.expect/manipulatorsInput.arm64.txt

    rc75b30a r32490deb  
    181812 wwwwwwww
    191913 wwwwwwww
    20 14 rc=1, cccc
     2014 rc=0, q
    212115 rc=0, q
    222216 get this line
    232317 @# this line 1)-{}
    24 18 abc
    25 19 abc 
    26 20  d d
     2418 @# this line 1)-{}
     2519 abc
     2620 abc 
     2721  d d
    2728
    2829d
    29 21              ZC44%
     3022              ZC44%
     3123              ZC44%
     3224 x
     3325 x
     3426 x
     3527 x
     3628 x
    30371 yyyyyyyyyyyyyyyyyyyy
    31382 abcxxx
    32393 abcxxx
    33404 aaaaaaaa
    34 5
     415 aaaaaaaa
    35426 aabbccbb
    36437 dddwww
    37 8
    38 9
     448 dddwww
     459 dddwww
    394610 aaaaaaaa
    404711 wwwwwwww
    41 12
    42 13
    43 14 cccc
     4812 wwwwwwww
     4913 wwwwwwww
     5014
    445115
    455216 get this line
    465317 @# this line 1)-{}
    47 18 abc
    48 19 abc 
    49 20 d d
     5418 @# this line 1)-{}
     5519 abc
     5620 abc 
     5721 d d
    5058
    5159d
    52 21              ZC44%
     6022              ZC44%
     6123              ZC44%
     6224 x
     6325 x
     6426 x
     6527 x
     6628 x
    5367a
    5468a
     69xxx
     70xxx
    5571-1
    567215
  • tests/io/.expect/manipulatorsInput.x64.txt

    rc75b30a r32490deb  
    181812 wwwwwwww
    191913 wwwwwwww
    20 14 rc=1, cccc
     2014 rc=0, q
    212115 rc=0, q
    222216 get this line
    232317 @# this line 1)-{}
    24 18 abc
    25 19 abc 
    26 20  d d
     2418 @# this line 1)-{}
     2519 abc
     2620 abc 
     2721  d d
    2728
    2829d
    29 21              ZC44%
     3022              ZC44%
     3123              ZC44%
     3224 x
     3325 x
     3426 x
     3527 x
     3628 x
    30371 yyyyyyyyyyyyyyyyyyyy
    31382 abcxxx
    32393 abcxxx
    33404 aaaaaaaa
    34 5
     415 aaaaaaaa
    35426 aabbccbb
    36437 dddwww
    37 8
    38 9
     448 dddwww
     459 dddwww
    394610 aaaaaaaa
    404711 wwwwwwww
    41 12
    42 13
    43 14 cccc
     4812 wwwwwwww
     4913 wwwwwwww
     5014
    445115
    455216 get this line
    465317 @# this line 1)-{}
    47 18 abc
    48 19 abc 
    49 20 d d
     5418 @# this line 1)-{}
     5519 abc
     5620 abc 
     5721 d d
    5058
    5159d
    52 21              ZC44%
     6022              ZC44%
     6123              ZC44%
     6224 x
     6325 x
     6426 x
     6527 x
     6628 x
    5367a
    5468a
     69xxx
     70xxx
    5571-1
    567215
  • tests/io/.expect/manipulatorsInput.x86.txt

    rc75b30a r32490deb  
    181812 wwwwwwww
    191913 wwwwwwww
    20 14 rc=1, cccc
     2014 rc=0, q
    212115 rc=0, q
    222216 get this line
    232317 @# this line 1)-{}
    24 18 abc
    25 19 abc 
    26 20  d d
     2418 @# this line 1)-{}
     2519 abc
     2620 abc 
     2721  d d
    2728
    2829d
    29 21              ZC44%
     3022              ZC44%
     3123              ZC44%
     3224 x
     3325 x
     3426 x
     3527 x
     3628 x
    30371 yyyyyyyyyyyyyyyyyyyy
    31382 abcxxx
    32393 abcxxx
    33404 aaaaaaaa
    34 5
     415 aaaaaaaa
    35426 aabbccbb
    36437 dddwww
    37 8
    38 9
     448 dddwww
     459 dddwww
    394610 aaaaaaaa
    404711 wwwwwwww
    41 12
    42 13
    43 14 cccc
     4812 wwwwwwww
     4913 wwwwwwww
     5014
    445115
    455216 get this line
    465317 @# this line 1)-{}
    47 18 abc
    48 19 abc 
    49 20 d d
     5418 @# this line 1)-{}
     5519 abc
     5620 abc 
     5721 d d
    5058
    5159d
    52 21              ZC44%
     6022              ZC44%
     6123              ZC44%
     6224 x
     6325 x
     6426 x
     6527 x
     6628 x
    5367a
    5468a
     69xxx
     70xxx
    5571-1
    567215
  • tests/io/.in/manipulatorsInput.txt

    rc75b30a r32490deb  
    88abcxxx
    99abcyyy
    10 aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    11 uuuuuccccuuuuu
     10aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
     11uuuuu
    1212get this line
    1313@# this line 1)-{}%
     14@# this line 2)-{}%
    1415"abc"
    1516'abc  '
     
    1819d }
    1920X               ZC44%Y
     21X               ZC55%Y
     22'x'
     23"x"
     24{x}
     25XxY
     26XyY
    2027abc
    2128cccccb
     
    2330abcxxx
    2431abcyyy
    25 aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwww
    26 uuuuuccccuuuuu
     32aaaaaaaaxxxxxxxxaabbccbbdddwwwbbbbbbbbwwwwwwwwaaaaaaaawwwwwwwwaaaaaaaawwwwwwww
     33uuuuu
    2734get this line
    2835@# this line 1)-{}%
     36@# this line 2)-{}%
    2937"abc"
    3038'abc  '
     
    3341d }
    3442X               ZC44%Y
     43X               ZC55%Y
     44'x'
     45"x"
     46{x}
     47XxY
     48XyY
    3549ab
     50xxxyyy
    36510xff 017 15-15
    37520xff 017 15-15
  • tests/io/manipulatorsInput.cfa

    rc75b30a r32490deb  
    77// Created On       : Sat Jun  8 17:58:54 2019
    88// Last Modified By : Peter A. Buhr
    9 // Last Modified On : Wed Jan  3 11:15:04 2024
    10 // Update Count     : 103
     9// Last Modified On : Sun Jan 28 11:59:55 2024
     10// Update Count     : 133
    1111//
    1212
     
    5555        }
    5656        {
    57                 char s[] = "yyyyyyyyyyyyyyyyyyyy";
     57                char s[] = "yyyyyyyyyyyyyyyyyyyy";                                                                                                      // Input characters consumed:
    5858                const char sk_fmt[] = "%*[abc]";
    59                 scanf( "abc " ); scanf( sk_fmt ); for ( 5 ) scanf( "%*c" ); printf( "1 %s\n", s );
    60                 scanf( "%s", s );                                                               printf( "2 %s\n", s );
    61                 scanf( "%*s" );                                                                 printf( "3 %s\n", s );
    62                 scanf( "%8s", s );                                                              printf( "4 %s\n", s );
    63                 scanf( "%*8s" );                                                                printf( "5 %s\n", s );
    64 
    65                 scanf( "%[abc]", s );                                                   printf( "6 %s\n", s );
    66                 scanf( "%[^abc]", s );                                                  printf( "7 %s\n", s );
    67                 scanf( "%*[abc]" );                                                             printf( "8 %s\n", s );
    68                 scanf( "%*[^abc]" );                                                    printf( "9 %s\n", s );
    69                 scanf( "%8[abc]", s );                                                  printf( "10 %s\n", s );
    70                 scanf( "%8[^abc]", s );                                                 printf( "11 %s\n", s );
    71                 scanf( "%*8[abc]" );                                                    printf( "12 %s\n", s );
    72                 scanf( "%*8[^abc]" );                                                   printf( "13 %s\n", s );
     59                scanf( "abc " ); scanf( sk_fmt ); for ( 5 ) scanf( "%*c" ); printf( "1 %s\n", s );      // |abc |\ncccccb| \nxx\n|
     60                scanf( "%s", s );                                                               printf( "2 %s\n", s );                          // |abcxxx|
     61                scanf( "%*s" );                                                                 printf( "3 %s\n", s );                          // |\nabcyyy|
     62                scanf( "%8s", s );                                                              printf( "4 %s\n", s );                          // |\naaaaaaaa|
     63                scanf( "%*8s" );                                                                printf( "5 %s\n", s );                          // |xxxxxxxx|
     64
     65                scanf( "%[abc]", s );                                                   printf( "6 %s\n", s );                          // |aabbccbb|
     66                scanf( "%[^abc]", s );                                                  printf( "7 %s\n", s );                          // |dddwww|
     67                scanf( "%*[abc]" );                                                             printf( "8 %s\n", s );                          // |bbbbbbbb|
     68                scanf( "%*[^abc]" );                                                    printf( "9 %s\n", s );                          // |wwwwwwww|
     69                scanf( "%8[abc]", s );                                                  printf( "10 %s\n", s );                         // |aaaaaaaa|
     70                scanf( "%8[^abc]", s );                                                 printf( "11 %s\n", s );                         // |wwwwwwww|
     71                scanf( "%*8[abc]" );                                                    printf( "12 %s\n", s );                         // |aaaaaaaa|
     72                scanf( "%*8[^abc]" );                                                   printf( "13 %s\n", s );                         // |wwwwwwww|
     73                scanf( "\n" );                                                                  // must start next line                         // |\n|
    7374
    7475                int rc;
    7576                s[0] = 'q'; s[1] = '\0'; rc = 99;
    76                 rc = scanf( "%[abc]", s );                                              printf( "14 rc=%d, %s\n", rc, s );
     77                rc = scanf( "%[abc]", s );                                              printf( "14 rc=%d, %s\n", rc, s );      // ||
    7778                s[0] = 'q'; s[1] = '\0'; rc = 99;
    78                 rc = scanf( "%[^u]", s );                                               printf( "15 rc=%d, %s\n", rc, s );
    79                 scanf( "%*[u]\n" );
    80                 scanf( "%[^\n]\n", s );                                                 printf( "16 %s\n", s );
    81                 scanf( "%[^%%]%%\n", s );                                               printf( "17 %s\n", s );
    82 
    83                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace
    84                 scanf( "\"%[^\"]\"", s );                                               printf( "18 %s\n", s );
    85                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace
    86                 scanf( "'%[^']'", s );                                                  printf( "19 %s\n", s );
    87                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace
    88                 scanf( "{%[^}]}", s );                                                  printf( "20 %s\n", s );
    89                 scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace
    90                 scanf( "X%[^Y]Y", s );                                                  printf( "21 %s\n", s );
    91                 scanf( "\n" );                                                                  // must start next line
     79                rc = scanf( "%[^u]", s );                                               printf( "15 rc=%d, %s\n", rc, s );      // ||
     80                scanf( "%*[u]\n" );                                                                                                                                     // |uuuuu\n|
     81                scanf( "%[^\n]\n", s );                                                 printf( "16 %s\n", s );                         // |get this line\n|
     82                scanf( "%[^%%]%%\n", s );                                               printf( "17 %s\n", s );                         // |@# this line 1)-{}%\n|
     83                scanf( "%*[^%%]%%\n", s );                                              printf( "18 %s\n", s );                         // |@# this line 1)-{}%\n|
     84
     85                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // ||
     86                scanf( "\"%[^\"]\"", s );                                               printf( "19 %s\n", s );                         // |"abc"|
     87                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     88                scanf( "'%[^']'", s );                                                  printf( "20 %s\n", s );                         // |'abc  '|
     89                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     90                scanf( "{%[^}]}", s );                                                  printf( "21 %s\n", s );                         // |{ d d\n\nd }|
     91                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     92                scanf( "X%[^Y]Y", s );                                                  printf( "22 %s\n", s );                         // |X           ZC44%Y|
     93                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     94                scanf( "X%*[^Y]Y", s );                                                 printf( "23 %s\n", s );                         // |X           ZC44%Y|
     95                scanf( "\n" );                                                                  // must start next line                         // |\n|
     96
     97                char ch;
     98                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     99                scanf( "'%c'", &ch );                                                   printf( "24 %c\n", ch );                        // |x|
     100                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     101                scanf( "\"%c\"", &ch );                                                 printf( "25 %c\n", ch );                        // |x|
     102                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     103                scanf( "{%c}", &ch );                                                   printf( "26 %c\n", ch );                        // |x|
     104                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     105                scanf( "X%cY", &ch );                                                   printf( "27 %c\n", ch );                        // |x|
     106                scanf( "%*[ \f\n\r\t\v]" );                                             // ignore whitespace                            // |\n|
     107                scanf( "X%*cY", &ch );                                                  printf( "28 %c\n", ch );                        // |x|
     108                scanf( "\n" );                                                                  // must start next line                         // |\n|
    92109        }
    93110        {
     
    108125                sin | ignore( incl( "abc", wdi( sizeof(s), 8, s ) ) ); sout | "12" | s;
    109126                sin | ignore( excl( "abc", wdi( sizeof(s), 8, s ) ) ); sout | "13" | s;
     127                sin | nl;
    110128
    111129                s[0] = 'q'; s[1] = '\0';
     
    116134                sin | getline( wdi( sizeof(s), s ) );                   sout | "16" | s;
    117135                sin | getline( wdi( sizeof(s), s ), '%' ) | "\n"; sout | "17" | s;
    118 
    119                 sin | quoted( wdi( sizeof(s), s ) );                    sout | "18" | s;
    120                 sin | quoted( wdi( sizeof(s), s ), '\'' );              sout | "19" | s;
    121                 sin | quoted( wdi( sizeof(s), s ), '{', '}' );  sout | "20" | s;
    122                 sin | quoted( wdi( sizeof(s), s ), 'X', 'Y' );  sout | "21" | s;
    123         }
    124     // Keep harmonized with collections/string-istream-manip
     136                sin | ignore( getline( wdi( sizeof(s), s ), '%' ) ) | "\n"; sout | "18" | s;
     137
     138                sin | quoted( wdi( sizeof(s), s ) );                    sout | "19" | s;
     139                sin | quoted( wdi( sizeof(s), s ), '\'' );              sout | "20" | s;
     140                sin | quoted( wdi( sizeof(s), s ), '{', '}' );  sout | "21" | s;
     141                sin | quoted( wdi( sizeof(s), s ), 'X', 'Y' );  sout | "22" | s;
     142                sin | ignore( quoted( wdi( sizeof(s), s ), 'X', 'Y' ) ); sout | "23" | s;
     143
     144                char ch;
     145                sin | quoted( ch );                                                             sout | "24 " | ch;
     146                sin | quoted( ch, '\"' );                                               sout | "25 " | ch;
     147                sin | quoted( ch, '{', '}' );                                   sout | "26 " | ch;
     148                sin | quoted( ch, 'X', 'Y' );                                   sout | "27 " | ch;
     149                sin | ignore( quoted( ch, 'X', 'Y' ) );                 sout | "28 " | ch;
     150                sin | nl;
     151        }
     152        // Keep harmonized with collections/string-istream-manip
    125153        {
    126154                char c;
    127155                sin | c;                                                                                sout | c;
    128156                sin | ignore( c );                                                              sout | c;
     157                sin | nl;
     158
     159                char ca[3] = { 'a', 'b', 'c' };
     160                sin | wdi( sizeof(ca), ca[0] );                                 sout | ca[0] | ca[1] | ca[2];
     161                sin | ignore( wdi( sizeof(ca), ca[0] ) );               sout | ca[0] | ca[1] | ca[2];
     162                sin | nl;
    129163
    130164                signed char sc;
Note: See TracChangeset for help on using the changeset viewer.