diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2023-03-26 21:11:42 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2023-03-26 21:11:42 +0300 |
commit | bafdbc1bb6da942a5099d884466e9bfc4c2af7bc (patch) | |
tree | f78a2ef2e6f90cd2a6725f2558a4828f5bf5adf8 | |
parent | 4980a6f43dbb6816d999e174e982ea6dd1b2d579 (diff) | |
parent | c73b1c59e9b5da4874d95ca3484aa87891376ca3 (diff) | |
download | gawk-bafdbc1bb6da942a5099d884466e9bfc4c2af7bc.tar.gz |
Merge branch 'gawk-5.2-stable'
-rw-r--r-- | doc/ChangeLog | 2 | ||||
-rw-r--r-- | doc/gawk.info | 695 | ||||
-rw-r--r-- | doc/gawk.texi | 55 | ||||
-rw-r--r-- | doc/gawktexi.in | 55 |
4 files changed, 477 insertions, 330 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index ce8b527d..526dad5d 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,8 @@ 2023-03-26 Arnold D. Robbins <arnold@skeeve.com> * texinfo.tex: Sync from GNULIB. + * gawktexi.in (Dynamic Typing): Add more explanation and another + example. 2023-03-23 Arnold D. Robbins <arnold@skeeve.com> diff --git a/doc/gawk.info b/doc/gawk.info index 8caf05b1..87f9eb34 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -15507,8 +15507,51 @@ Here is an annotated sample program: so ‘awk’ will not report the second error. If you comment out that call, though, then ‘awk’ does report the second error. - Usually, such things aren’t a big issue, but it’s worth being aware -of them. + Here is a more extreme example: + + BEGIN { + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] + } + + function funky(arr) + { + if (A == 0) + arr = 1 + else + arr[1] = 1 + } + + Here, the function uses its parameter differently depending upon the +value of the global variable ‘A’. If ‘A’ is zero, the parameter ‘arr’ +is treated as a scalar. Otherwise it’s treated as an array. + + There are two ways this program might behave. ‘awk’ could notice +that in the main program, ‘a’ is subscripted, and so mark it as an array +before the program even begins to run. BWK ‘awk’, ‘mawk’, and possibly +others do this: + + $ nawk -v A=0 -f funky.awk + error→ nawk: can't assign to a; it's an array name. + error→ source line number 11 + $ nawk -v A=1 -f funky.awk + ⊣ 1 + + Or ‘awk’ could wait until runtime to set the type of ‘a’. In this +case, since ‘a’ was never assigned used before being passed to the +function, how the function uses it forces the type to be resolved to +either scalar or array. ‘gawk’ and the MKS ‘awk’ do this: + + $ gawk -v A=0 -f funky.awk + ⊣ <> + $ gawk -v A=1 -f funky.awk + ⊣ 1 + + POSIX does not specify the correct behavior, so be aware that +different implementations work differently. File: gawk.info, Node: Indirect Calls, Next: Functions Summary, Prev: User-defined, Up: Functions @@ -39805,330 +39848,330 @@ Node: Function Caveats669709 Ref: Function Caveats-Footnote-1671804 Node: Return Statement671928 Node: Dynamic Typing674983 -Node: Indirect Calls675939 -Node: Functions Summary687098 -Node: Library Functions689875 -Ref: Library Functions-Footnote-1693423 -Ref: Library Functions-Footnote-2693566 -Node: Library Names693741 -Ref: Library Names-Footnote-1697535 -Ref: Library Names-Footnote-2697762 -Node: General Functions697858 -Node: Strtonum Function699052 -Node: Assert Function702134 -Node: Round Function705586 -Node: Cliff Random Function707164 -Node: Ordinal Functions708197 -Ref: Ordinal Functions-Footnote-1711306 -Ref: Ordinal Functions-Footnote-2711558 -Node: Join Function711772 -Ref: Join Function-Footnote-1713575 -Node: Getlocaltime Function713779 -Node: Readfile Function717553 -Node: Shell Quoting719582 -Node: Isnumeric Function721038 -Node: Data File Management722450 -Node: Filetrans Function723082 -Node: Rewind Function727376 -Node: File Checking729355 -Ref: File Checking-Footnote-1730727 -Node: Empty Files730934 -Node: Ignoring Assigns733001 -Node: Getopt Function734575 -Ref: Getopt Function-Footnote-1750409 -Node: Passwd Functions750621 -Ref: Passwd Functions-Footnote-1759803 -Node: Group Functions759891 -Ref: Group Functions-Footnote-1768029 -Node: Walking Arrays768242 -Node: Library Functions Summary771290 -Node: Library Exercises772714 -Node: Sample Programs773201 -Node: Running Examples773983 -Node: Clones774735 -Node: Cut Program776007 -Node: Egrep Program786448 -Node: Id Program795765 -Node: Split Program805879 -Ref: Split Program-Footnote-1816114 -Node: Tee Program816301 -Node: Uniq Program819210 -Node: Wc Program827075 -Node: Bytes vs. Characters827470 -Node: Using extensions829072 -Node: wc program829852 -Node: Miscellaneous Programs834858 -Node: Dupword Program836087 -Node: Alarm Program838150 -Node: Translate Program843063 -Ref: Translate Program-Footnote-1847804 -Node: Labels Program848082 -Ref: Labels Program-Footnote-1851523 -Node: Word Sorting851615 -Node: History Sorting855809 -Node: Extract Program858084 -Node: Simple Sed866353 -Node: Igawk Program869569 -Ref: Igawk Program-Footnote-1884816 -Ref: Igawk Program-Footnote-2885022 -Ref: Igawk Program-Footnote-3885152 -Node: Anagram Program885279 -Node: Signature Program888375 -Node: Programs Summary889627 -Node: Programs Exercises890885 -Ref: Programs Exercises-Footnote-1895201 -Node: Advanced Features895287 -Node: Nondecimal Data897781 -Node: Boolean Typed Values899411 -Node: Array Sorting901386 -Node: Controlling Array Traversal902115 -Ref: Controlling Array Traversal-Footnote-1910622 -Node: Array Sorting Functions910744 -Ref: Array Sorting Functions-Footnote-1916863 -Node: Two-way I/O917071 -Ref: Two-way I/O-Footnote-1925066 -Ref: Two-way I/O-Footnote-2925257 -Node: TCP/IP Networking925339 -Node: Profiling928519 -Node: Persistent Memory938229 -Ref: Persistent Memory-Footnote-1947187 -Node: Extension Philosophy947318 -Node: Advanced Features Summary948853 -Node: Internationalization951123 -Node: I18N and L10N952829 -Node: Explaining gettext953524 -Ref: Explaining gettext-Footnote-1959677 -Ref: Explaining gettext-Footnote-2959872 -Node: Programmer i18n960037 -Ref: Programmer i18n-Footnote-1965150 -Node: Translator i18n965199 -Node: String Extraction966035 -Ref: String Extraction-Footnote-1967213 -Node: Printf Ordering967311 -Ref: Printf Ordering-Footnote-1970173 -Node: I18N Portability970241 -Ref: I18N Portability-Footnote-1972815 -Node: I18N Example972886 -Ref: I18N Example-Footnote-1976286 -Ref: I18N Example-Footnote-2976362 -Node: Gawk I18N976479 -Node: I18N Summary977135 -Node: Debugger978536 -Node: Debugging979560 -Node: Debugging Concepts980009 -Node: Debugging Terms981835 -Node: Awk Debugging984448 -Ref: Awk Debugging-Footnote-1985425 -Node: Sample Debugging Session985565 -Node: Debugger Invocation986117 -Node: Finding The Bug987746 -Node: List of Debugger Commands994432 -Node: Breakpoint Control995809 -Node: Debugger Execution Control999641 -Node: Viewing And Changing Data1003121 -Node: Execution Stack1006859 -Node: Debugger Info1008540 -Node: Miscellaneous Debugger Commands1012839 -Node: Readline Support1018092 -Node: Limitations1019038 -Node: Debugging Summary1021682 -Node: Namespaces1022985 -Node: Global Namespace1024112 -Node: Qualified Names1025557 -Node: Default Namespace1026592 -Node: Changing The Namespace1027367 -Node: Naming Rules1029061 -Node: Internal Name Management1030976 -Node: Namespace Example1032046 -Node: Namespace And Features1034629 -Node: Namespace Summary1036086 -Node: Arbitrary Precision Arithmetic1037599 -Node: Computer Arithmetic1039118 -Ref: table-numeric-ranges1042935 -Ref: table-floating-point-ranges1043433 -Ref: Computer Arithmetic-Footnote-11044092 -Node: Math Definitions1044151 -Ref: table-ieee-formats1047196 -Node: MPFR features1047770 -Node: MPFR On Parole1048223 -Ref: MPFR On Parole-Footnote-11049067 -Node: MPFR Intro1049226 -Node: FP Math Caution1050916 -Ref: FP Math Caution-Footnote-11051990 -Node: Inexactness of computations1052367 -Node: Inexact representation1053398 -Node: Comparing FP Values1054781 -Node: Errors accumulate1056039 -Node: Strange values1057506 -Ref: Strange values-Footnote-11060172 -Node: Getting Accuracy1060277 -Node: Try To Round1063014 -Node: Setting precision1063921 -Ref: table-predefined-precision-strings1064626 -Node: Setting the rounding mode1066511 -Ref: table-gawk-rounding-modes1066893 -Ref: Setting the rounding mode-Footnote-11070951 -Node: Arbitrary Precision Integers1071134 -Ref: Arbitrary Precision Integers-Footnote-11074346 -Node: Checking for MPFR1074502 -Node: POSIX Floating Point Problems1075992 -Ref: POSIX Floating Point Problems-Footnote-11080856 -Node: Floating point summary1080894 -Node: Dynamic Extensions1083158 -Node: Extension Intro1084757 -Node: Plugin License1086065 -Node: Extension Mechanism Outline1086878 -Ref: figure-load-extension1087329 -Ref: figure-register-new-function1088914 -Ref: figure-call-new-function1090024 -Node: Extension API Description1092148 -Node: Extension API Functions Introduction1093877 -Ref: table-api-std-headers1095775 -Node: General Data Types1100239 -Ref: General Data Types-Footnote-11109407 -Node: Memory Allocation Functions1109722 -Ref: Memory Allocation Functions-Footnote-11114447 -Node: Constructor Functions1114546 -Node: API Ownership of MPFR and GMP Values1118451 -Node: Registration Functions1120012 -Node: Extension Functions1120716 -Node: Exit Callback Functions1126292 -Node: Extension Version String1127611 -Node: Input Parsers1128306 -Node: Output Wrappers1142950 -Node: Two-way processors1147798 -Node: Printing Messages1150159 -Ref: Printing Messages-Footnote-11151373 -Node: Updating ERRNO1151528 -Node: Requesting Values1152327 -Ref: table-value-types-returned1153080 -Node: Accessing Parameters1154189 -Node: Symbol Table Access1155473 -Node: Symbol table by name1155989 -Ref: Symbol table by name-Footnote-11159200 -Node: Symbol table by cookie1159332 -Ref: Symbol table by cookie-Footnote-11163613 -Node: Cached values1163677 -Ref: Cached values-Footnote-11167321 -Node: Array Manipulation1167478 -Ref: Array Manipulation-Footnote-11168581 -Node: Array Data Types1168618 -Ref: Array Data Types-Footnote-11171440 -Node: Array Functions1171540 -Node: Flattening Arrays1176569 -Node: Creating Arrays1183621 -Node: Redirection API1188471 -Node: Extension API Variables1191492 -Node: Extension Versioning1192217 -Ref: gawk-api-version1192654 -Node: Extension GMP/MPFR Versioning1194442 -Node: Extension API Informational Variables1196148 -Node: Extension API Boilerplate1197309 -Node: Changes from API V11201445 -Node: Finding Extensions1203079 -Node: Extension Example1203654 -Node: Internal File Description1204478 -Node: Internal File Ops1208802 -Ref: Internal File Ops-Footnote-11220360 -Node: Using Internal File Ops1220508 -Ref: Using Internal File Ops-Footnote-11222939 -Node: Extension Samples1223217 -Node: Extension Sample File Functions1224786 -Node: Extension Sample Fnmatch1232924 -Node: Extension Sample Fork1234519 -Node: Extension Sample Inplace1235795 -Node: Extension Sample Ord1239467 -Node: Extension Sample Readdir1240343 -Ref: table-readdir-file-types1241240 -Node: Extension Sample Revout1242378 -Node: Extension Sample Rev2way1242975 -Node: Extension Sample Read write array1243727 -Node: Extension Sample Readfile1247001 -Node: Extension Sample Time1248132 -Node: Extension Sample API Tests1250422 -Node: gawkextlib1250930 -Node: Extension summary1253966 -Node: Extension Exercises1257824 -Node: Language History1259102 -Node: V7/SVR3.11260816 -Node: SVR41263166 -Node: POSIX1264698 -Node: BTL1266123 -Node: POSIX/GNU1266892 -Node: Feature History1273423 -Node: Common Extensions1292989 -Node: Ranges and Locales1294358 -Ref: Ranges and Locales-Footnote-11299159 -Ref: Ranges and Locales-Footnote-21299186 -Ref: Ranges and Locales-Footnote-31299425 -Node: Contributors1299648 -Node: History summary1305853 -Node: Installation1307299 -Node: Gawk Distribution1308263 -Node: Getting1308755 -Node: Extracting1309754 -Node: Distribution contents1311466 -Node: Unix Installation1319546 -Node: Quick Installation1320368 -Node: Compiling with MPFR1322914 -Node: Shell Startup Files1323620 -Node: Additional Configuration Options1324777 -Node: Configuration Philosophy1327164 -Node: Compiling from Git1329666 -Node: Building the Documentation1330225 -Node: Non-Unix Installation1331637 -Node: PC Installation1332113 -Node: PC Binary Installation1332986 -Node: PC Compiling1333891 -Node: PC Using1335069 -Node: Cygwin1338797 -Node: MSYS1340053 -Node: OpenVMS Installation1340685 -Node: OpenVMS Compilation1341366 -Ref: OpenVMS Compilation-Footnote-11342849 -Node: OpenVMS Dynamic Extensions1342911 -Node: OpenVMS Installation Details1344547 -Node: OpenVMS Running1346982 -Node: OpenVMS GNV1351119 -Node: Bugs1351874 -Node: Bug definition1352798 -Node: Bug address1356449 -Node: Usenet1360040 -Node: Performance bugs1361271 -Node: Asking for help1364289 -Node: Maintainers1366280 -Node: Other Versions1367307 -Node: Installation summary1376239 -Node: Notes1377623 -Node: Compatibility Mode1378433 -Node: Additions1379255 -Node: Accessing The Source1380200 -Node: Adding Code1381735 -Node: New Ports1388871 -Node: Derived Files1393381 -Ref: Derived Files-Footnote-11399228 -Ref: Derived Files-Footnote-21399263 -Ref: Derived Files-Footnote-31399880 -Node: Future Extensions1399994 -Node: Implementation Limitations1400666 -Node: Extension Design1401908 -Node: Old Extension Problems1403072 -Ref: Old Extension Problems-Footnote-11404648 -Node: Extension New Mechanism Goals1404709 -Ref: Extension New Mechanism Goals-Footnote-11408205 -Node: Extension Other Design Decisions1408406 -Node: Extension Future Growth1410605 -Node: Notes summary1411229 -Node: Basic Concepts1412442 -Node: Basic High Level1413127 -Ref: figure-general-flow1413409 -Ref: figure-process-flow1414116 -Ref: Basic High Level-Footnote-11417517 -Node: Basic Data Typing1417706 -Node: Glossary1421124 -Node: Copying1454246 -Node: GNU Free Documentation License1492007 -Node: Index1517330 +Node: Indirect Calls677259 +Node: Functions Summary688418 +Node: Library Functions691195 +Ref: Library Functions-Footnote-1694743 +Ref: Library Functions-Footnote-2694886 +Node: Library Names695061 +Ref: Library Names-Footnote-1698855 +Ref: Library Names-Footnote-2699082 +Node: General Functions699178 +Node: Strtonum Function700372 +Node: Assert Function703454 +Node: Round Function706906 +Node: Cliff Random Function708484 +Node: Ordinal Functions709517 +Ref: Ordinal Functions-Footnote-1712626 +Ref: Ordinal Functions-Footnote-2712878 +Node: Join Function713092 +Ref: Join Function-Footnote-1714895 +Node: Getlocaltime Function715099 +Node: Readfile Function718873 +Node: Shell Quoting720902 +Node: Isnumeric Function722358 +Node: Data File Management723770 +Node: Filetrans Function724402 +Node: Rewind Function728696 +Node: File Checking730675 +Ref: File Checking-Footnote-1732047 +Node: Empty Files732254 +Node: Ignoring Assigns734321 +Node: Getopt Function735895 +Ref: Getopt Function-Footnote-1751729 +Node: Passwd Functions751941 +Ref: Passwd Functions-Footnote-1761123 +Node: Group Functions761211 +Ref: Group Functions-Footnote-1769349 +Node: Walking Arrays769562 +Node: Library Functions Summary772610 +Node: Library Exercises774034 +Node: Sample Programs774521 +Node: Running Examples775303 +Node: Clones776055 +Node: Cut Program777327 +Node: Egrep Program787768 +Node: Id Program797085 +Node: Split Program807199 +Ref: Split Program-Footnote-1817434 +Node: Tee Program817621 +Node: Uniq Program820530 +Node: Wc Program828395 +Node: Bytes vs. Characters828790 +Node: Using extensions830392 +Node: wc program831172 +Node: Miscellaneous Programs836178 +Node: Dupword Program837407 +Node: Alarm Program839470 +Node: Translate Program844383 +Ref: Translate Program-Footnote-1849124 +Node: Labels Program849402 +Ref: Labels Program-Footnote-1852843 +Node: Word Sorting852935 +Node: History Sorting857129 +Node: Extract Program859404 +Node: Simple Sed867673 +Node: Igawk Program870889 +Ref: Igawk Program-Footnote-1886136 +Ref: Igawk Program-Footnote-2886342 +Ref: Igawk Program-Footnote-3886472 +Node: Anagram Program886599 +Node: Signature Program889695 +Node: Programs Summary890947 +Node: Programs Exercises892205 +Ref: Programs Exercises-Footnote-1896521 +Node: Advanced Features896607 +Node: Nondecimal Data899101 +Node: Boolean Typed Values900731 +Node: Array Sorting902706 +Node: Controlling Array Traversal903435 +Ref: Controlling Array Traversal-Footnote-1911942 +Node: Array Sorting Functions912064 +Ref: Array Sorting Functions-Footnote-1918183 +Node: Two-way I/O918391 +Ref: Two-way I/O-Footnote-1926386 +Ref: Two-way I/O-Footnote-2926577 +Node: TCP/IP Networking926659 +Node: Profiling929839 +Node: Persistent Memory939549 +Ref: Persistent Memory-Footnote-1948507 +Node: Extension Philosophy948638 +Node: Advanced Features Summary950173 +Node: Internationalization952443 +Node: I18N and L10N954149 +Node: Explaining gettext954844 +Ref: Explaining gettext-Footnote-1960997 +Ref: Explaining gettext-Footnote-2961192 +Node: Programmer i18n961357 +Ref: Programmer i18n-Footnote-1966470 +Node: Translator i18n966519 +Node: String Extraction967355 +Ref: String Extraction-Footnote-1968533 +Node: Printf Ordering968631 +Ref: Printf Ordering-Footnote-1971493 +Node: I18N Portability971561 +Ref: I18N Portability-Footnote-1974135 +Node: I18N Example974206 +Ref: I18N Example-Footnote-1977606 +Ref: I18N Example-Footnote-2977682 +Node: Gawk I18N977799 +Node: I18N Summary978455 +Node: Debugger979856 +Node: Debugging980880 +Node: Debugging Concepts981329 +Node: Debugging Terms983155 +Node: Awk Debugging985768 +Ref: Awk Debugging-Footnote-1986745 +Node: Sample Debugging Session986885 +Node: Debugger Invocation987437 +Node: Finding The Bug989066 +Node: List of Debugger Commands995752 +Node: Breakpoint Control997129 +Node: Debugger Execution Control1000961 +Node: Viewing And Changing Data1004441 +Node: Execution Stack1008179 +Node: Debugger Info1009860 +Node: Miscellaneous Debugger Commands1014159 +Node: Readline Support1019412 +Node: Limitations1020358 +Node: Debugging Summary1023002 +Node: Namespaces1024305 +Node: Global Namespace1025432 +Node: Qualified Names1026877 +Node: Default Namespace1027912 +Node: Changing The Namespace1028687 +Node: Naming Rules1030381 +Node: Internal Name Management1032296 +Node: Namespace Example1033366 +Node: Namespace And Features1035949 +Node: Namespace Summary1037406 +Node: Arbitrary Precision Arithmetic1038919 +Node: Computer Arithmetic1040438 +Ref: table-numeric-ranges1044255 +Ref: table-floating-point-ranges1044753 +Ref: Computer Arithmetic-Footnote-11045412 +Node: Math Definitions1045471 +Ref: table-ieee-formats1048516 +Node: MPFR features1049090 +Node: MPFR On Parole1049543 +Ref: MPFR On Parole-Footnote-11050387 +Node: MPFR Intro1050546 +Node: FP Math Caution1052236 +Ref: FP Math Caution-Footnote-11053310 +Node: Inexactness of computations1053687 +Node: Inexact representation1054718 +Node: Comparing FP Values1056101 +Node: Errors accumulate1057359 +Node: Strange values1058826 +Ref: Strange values-Footnote-11061492 +Node: Getting Accuracy1061597 +Node: Try To Round1064334 +Node: Setting precision1065241 +Ref: table-predefined-precision-strings1065946 +Node: Setting the rounding mode1067831 +Ref: table-gawk-rounding-modes1068213 +Ref: Setting the rounding mode-Footnote-11072271 +Node: Arbitrary Precision Integers1072454 +Ref: Arbitrary Precision Integers-Footnote-11075666 +Node: Checking for MPFR1075822 +Node: POSIX Floating Point Problems1077312 +Ref: POSIX Floating Point Problems-Footnote-11082176 +Node: Floating point summary1082214 +Node: Dynamic Extensions1084478 +Node: Extension Intro1086077 +Node: Plugin License1087385 +Node: Extension Mechanism Outline1088198 +Ref: figure-load-extension1088649 +Ref: figure-register-new-function1090234 +Ref: figure-call-new-function1091344 +Node: Extension API Description1093468 +Node: Extension API Functions Introduction1095197 +Ref: table-api-std-headers1097095 +Node: General Data Types1101559 +Ref: General Data Types-Footnote-11110727 +Node: Memory Allocation Functions1111042 +Ref: Memory Allocation Functions-Footnote-11115767 +Node: Constructor Functions1115866 +Node: API Ownership of MPFR and GMP Values1119771 +Node: Registration Functions1121332 +Node: Extension Functions1122036 +Node: Exit Callback Functions1127612 +Node: Extension Version String1128931 +Node: Input Parsers1129626 +Node: Output Wrappers1144270 +Node: Two-way processors1149118 +Node: Printing Messages1151479 +Ref: Printing Messages-Footnote-11152693 +Node: Updating ERRNO1152848 +Node: Requesting Values1153647 +Ref: table-value-types-returned1154400 +Node: Accessing Parameters1155509 +Node: Symbol Table Access1156793 +Node: Symbol table by name1157309 +Ref: Symbol table by name-Footnote-11160520 +Node: Symbol table by cookie1160652 +Ref: Symbol table by cookie-Footnote-11164933 +Node: Cached values1164997 +Ref: Cached values-Footnote-11168641 +Node: Array Manipulation1168798 +Ref: Array Manipulation-Footnote-11169901 +Node: Array Data Types1169938 +Ref: Array Data Types-Footnote-11172760 +Node: Array Functions1172860 +Node: Flattening Arrays1177889 +Node: Creating Arrays1184941 +Node: Redirection API1189791 +Node: Extension API Variables1192812 +Node: Extension Versioning1193537 +Ref: gawk-api-version1193974 +Node: Extension GMP/MPFR Versioning1195762 +Node: Extension API Informational Variables1197468 +Node: Extension API Boilerplate1198629 +Node: Changes from API V11202765 +Node: Finding Extensions1204399 +Node: Extension Example1204974 +Node: Internal File Description1205798 +Node: Internal File Ops1210122 +Ref: Internal File Ops-Footnote-11221680 +Node: Using Internal File Ops1221828 +Ref: Using Internal File Ops-Footnote-11224259 +Node: Extension Samples1224537 +Node: Extension Sample File Functions1226106 +Node: Extension Sample Fnmatch1234244 +Node: Extension Sample Fork1235839 +Node: Extension Sample Inplace1237115 +Node: Extension Sample Ord1240787 +Node: Extension Sample Readdir1241663 +Ref: table-readdir-file-types1242560 +Node: Extension Sample Revout1243698 +Node: Extension Sample Rev2way1244295 +Node: Extension Sample Read write array1245047 +Node: Extension Sample Readfile1248321 +Node: Extension Sample Time1249452 +Node: Extension Sample API Tests1251742 +Node: gawkextlib1252250 +Node: Extension summary1255286 +Node: Extension Exercises1259144 +Node: Language History1260422 +Node: V7/SVR3.11262136 +Node: SVR41264486 +Node: POSIX1266018 +Node: BTL1267443 +Node: POSIX/GNU1268212 +Node: Feature History1274743 +Node: Common Extensions1294309 +Node: Ranges and Locales1295678 +Ref: Ranges and Locales-Footnote-11300479 +Ref: Ranges and Locales-Footnote-21300506 +Ref: Ranges and Locales-Footnote-31300745 +Node: Contributors1300968 +Node: History summary1307173 +Node: Installation1308619 +Node: Gawk Distribution1309583 +Node: Getting1310075 +Node: Extracting1311074 +Node: Distribution contents1312786 +Node: Unix Installation1320866 +Node: Quick Installation1321688 +Node: Compiling with MPFR1324234 +Node: Shell Startup Files1324940 +Node: Additional Configuration Options1326097 +Node: Configuration Philosophy1328484 +Node: Compiling from Git1330986 +Node: Building the Documentation1331545 +Node: Non-Unix Installation1332957 +Node: PC Installation1333433 +Node: PC Binary Installation1334306 +Node: PC Compiling1335211 +Node: PC Using1336389 +Node: Cygwin1340117 +Node: MSYS1341373 +Node: OpenVMS Installation1342005 +Node: OpenVMS Compilation1342686 +Ref: OpenVMS Compilation-Footnote-11344169 +Node: OpenVMS Dynamic Extensions1344231 +Node: OpenVMS Installation Details1345867 +Node: OpenVMS Running1348302 +Node: OpenVMS GNV1352439 +Node: Bugs1353194 +Node: Bug definition1354118 +Node: Bug address1357769 +Node: Usenet1361360 +Node: Performance bugs1362591 +Node: Asking for help1365609 +Node: Maintainers1367600 +Node: Other Versions1368627 +Node: Installation summary1377559 +Node: Notes1378943 +Node: Compatibility Mode1379753 +Node: Additions1380575 +Node: Accessing The Source1381520 +Node: Adding Code1383055 +Node: New Ports1390191 +Node: Derived Files1394701 +Ref: Derived Files-Footnote-11400548 +Ref: Derived Files-Footnote-21400583 +Ref: Derived Files-Footnote-31401200 +Node: Future Extensions1401314 +Node: Implementation Limitations1401986 +Node: Extension Design1403228 +Node: Old Extension Problems1404392 +Ref: Old Extension Problems-Footnote-11405968 +Node: Extension New Mechanism Goals1406029 +Ref: Extension New Mechanism Goals-Footnote-11409525 +Node: Extension Other Design Decisions1409726 +Node: Extension Future Growth1411925 +Node: Notes summary1412549 +Node: Basic Concepts1413762 +Node: Basic High Level1414447 +Ref: figure-general-flow1414729 +Ref: figure-process-flow1415436 +Ref: Basic High Level-Footnote-11418837 +Node: Basic Data Typing1419026 +Node: Glossary1422444 +Node: Copying1455566 +Node: GNU Free Documentation License1493327 +Node: Index1518650 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index 6db8af6a..b72cf068 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -22190,8 +22190,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls diff --git a/doc/gawktexi.in b/doc/gawktexi.in index bdb501e4..e6556684 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -21171,8 +21171,59 @@ a fatal error, so @command{awk} will not report the second error. If you comment out that call, though, then @command{awk} does report the second error. -Usually, such things aren't a big issue, but it's worth -being aware of them. +Here is a more extreme example: + +@example +BEGIN @{ + funky(a) + if (A == 0) + print "<" a ">" + else + print a[1] +@} + +function funky(arr) +@{ + if (A == 0) + arr = 1 + else + arr[1] = 1 +@} +@end example + +Here, the function uses its parameter differently depending upon the +value of the global variable @code{A}. If @code{A} is zero, the +parameter @code{arr} is treated as a scalar. Otherwise it's treated +as an array. + +There are two ways this program might behave. @command{awk} could notice +that in the main program, @code{a} is subscripted, and so mark it as +an array before the program even begins to run. BWK @code{awk}, @code{mawk}, +and possibly others do this: + +@example +$ @kbd{nawk -v A=0 -f funky.awk} +@error{} nawk: can't assign to a; it's an array name. +@error{} source line number 11 +$ @kbd{nawk -v A=1 -f funky.awk} +@print{} 1 +@end example + +Or @command{awk} could wait until runtime to set the type of @code{a}. +In this case, since @code{a} was never assigned used before being +passed to the function, how the function uses it forces the type to +be resolved to either scalar or array. @command{gawk} +and the MKS @command{awk} do this: + +@example +$ @kbd{gawk -v A=0 -f funky.awk} +@print{} <> +$ @kbd{gawk -v A=1 -f funky.awk } +@print{} 1 +@end example + +POSIX does not specify the correct behavior, so be aware that different +implementations work differently. @node Indirect Calls @section Indirect Function Calls |