diff options
-rw-r--r-- | doc/ChangeLog | 5 | ||||
-rw-r--r-- | doc/gawk.info | 652 | ||||
-rw-r--r-- | doc/gawk.texi | 28 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/Makefile.in | 9 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/getline5.awk | 35 | ||||
-rw-r--r-- | test/getline5.ok | 1 |
9 files changed, 426 insertions, 318 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index 56ec4ef1..e56c35a5 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2012-07-13 Arnold D. Robbins <arnold@skeeve.com> + + * gawk.texi (Getline Notes): Discuss side effects in + argument expression. + 2012-06-29 Arnold D. Robbins <arnold@skeeve.com> * gawk.texi, awkcard.in: Latest mawk understands /dev/stdin. diff --git a/doc/gawk.info b/doc/gawk.info index 5b063d78..c2781488 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -5200,6 +5200,26 @@ in mind: cause `FILENAME' to be updated if they cause `awk' to start reading a new input file. + * If the variable being assigned is an expression with side effects, + different versions of `awk' behave differently upon encountering + end-of-file. Some versions don't evaluate the expression; many + versions (including `gawk') do. Here is an example, due to Duncan + Moore: + + BEGIN { + system("echo 1 > f") + while ((getline a[++c] < "f") > 0) { } + print c + } + + Here, the side effect is the `++c'. Is `c' incremented if end of + file is encountered, before the element in `a' is assigned? + + `gawk' treats `getline' like a function call, and evaluates the + expression `a[++c]' before attempting to read from `f'. Other + versions of `awk' only evaluate the expression once they know that + there is a string value to be assigned. Caveat Emptor. + File: gawk.info, Node: Getline Summary, Prev: Getline Notes, Up: Getline @@ -27537,321 +27557,321 @@ Node: Getline/Variable/Pipe222455 Node: Getline/Coprocess223562 Node: Getline/Variable/Coprocess224805 Node: Getline Notes225519 -Node: Getline Summary227461 -Ref: table-getline-variants227804 -Node: Command line directories228660 -Node: Printing229285 -Node: Print230916 -Node: Print Examples232253 -Node: Output Separators235037 -Node: OFMT236797 -Node: Printf238155 -Node: Basic Printf239061 -Node: Control Letters240600 -Node: Format Modifiers244412 -Node: Printf Examples250421 -Node: Redirection253136 -Node: Special Files260120 -Node: Special FD260653 -Ref: Special FD-Footnote-1264278 -Node: Special Network264352 -Node: Special Caveats265202 -Node: Close Files And Pipes265998 -Ref: Close Files And Pipes-Footnote-1273021 -Ref: Close Files And Pipes-Footnote-2273169 -Node: Expressions273319 -Node: Values274451 -Node: Constants275127 -Node: Scalar Constants275807 -Ref: Scalar Constants-Footnote-1276666 -Node: Nondecimal-numbers276848 -Node: Regexp Constants279907 -Node: Using Constant Regexps280382 -Node: Variables283437 -Node: Using Variables284092 -Node: Assignment Options285816 -Node: Conversion287688 -Ref: table-locale-affects293064 -Ref: Conversion-Footnote-1293688 -Node: All Operators293797 -Node: Arithmetic Ops294427 -Node: Concatenation296932 -Ref: Concatenation-Footnote-1299725 -Node: Assignment Ops299845 -Ref: table-assign-ops304833 -Node: Increment Ops306241 -Node: Truth Values and Conditions309711 -Node: Truth Values310794 -Node: Typing and Comparison311843 -Node: Variable Typing312632 -Ref: Variable Typing-Footnote-1316529 -Node: Comparison Operators316651 -Ref: table-relational-ops317061 -Node: POSIX String Comparison320610 -Ref: POSIX String Comparison-Footnote-1321566 -Node: Boolean Ops321704 -Ref: Boolean Ops-Footnote-1325782 -Node: Conditional Exp325873 -Node: Function Calls327605 -Node: Precedence331199 -Node: Locales334868 -Node: Patterns and Actions335957 -Node: Pattern Overview337011 -Node: Regexp Patterns338680 -Node: Expression Patterns339223 -Node: Ranges342908 -Node: BEGIN/END345874 -Node: Using BEGIN/END346636 -Ref: Using BEGIN/END-Footnote-1349367 -Node: I/O And BEGIN/END349473 -Node: BEGINFILE/ENDFILE351755 -Node: Empty354648 -Node: Using Shell Variables354964 -Node: Action Overview357249 -Node: Statements359606 -Node: If Statement361460 -Node: While Statement362959 -Node: Do Statement365003 -Node: For Statement366159 -Node: Switch Statement369311 -Node: Break Statement371408 -Node: Continue Statement373398 -Node: Next Statement375191 -Node: Nextfile Statement377581 -Node: Exit Statement380126 -Node: Built-in Variables382542 -Node: User-modified383637 -Ref: User-modified-Footnote-1391663 -Node: Auto-set391725 -Ref: Auto-set-Footnote-1401016 -Node: ARGC and ARGV401221 -Node: Arrays405072 -Node: Array Basics406577 -Node: Array Intro407403 -Node: Reference to Elements411721 -Node: Assigning Elements413991 -Node: Array Example414482 -Node: Scanning an Array416214 -Node: Controlling Scanning418528 -Ref: Controlling Scanning-Footnote-1423461 -Node: Delete423777 -Ref: Delete-Footnote-1426212 -Node: Numeric Array Subscripts426269 -Node: Uninitialized Subscripts428452 -Node: Multi-dimensional430080 -Node: Multi-scanning433174 -Node: Arrays of Arrays434765 -Node: Functions439410 -Node: Built-in440232 -Node: Calling Built-in441310 -Node: Numeric Functions443298 -Ref: Numeric Functions-Footnote-1447130 -Ref: Numeric Functions-Footnote-2447487 -Ref: Numeric Functions-Footnote-3447535 -Node: String Functions447804 -Ref: String Functions-Footnote-1471301 -Ref: String Functions-Footnote-2471430 -Ref: String Functions-Footnote-3471678 -Node: Gory Details471765 -Ref: table-sub-escapes473444 -Ref: table-sub-posix-92474798 -Ref: table-sub-proposed476141 -Ref: table-posix-sub477491 -Ref: table-gensub-escapes479037 -Ref: Gory Details-Footnote-1480244 -Ref: Gory Details-Footnote-2480295 -Node: I/O Functions480446 -Ref: I/O Functions-Footnote-1487101 -Node: Time Functions487248 -Ref: Time Functions-Footnote-1498140 -Ref: Time Functions-Footnote-2498208 -Ref: Time Functions-Footnote-3498366 -Ref: Time Functions-Footnote-4498477 -Ref: Time Functions-Footnote-5498589 -Ref: Time Functions-Footnote-6498816 -Node: Bitwise Functions499082 -Ref: table-bitwise-ops499640 -Ref: Bitwise Functions-Footnote-1503800 -Node: Type Functions503984 -Node: I18N Functions504454 -Node: User-defined506081 -Node: Definition Syntax506885 -Ref: Definition Syntax-Footnote-1511795 -Node: Function Example511864 -Node: Function Caveats514458 -Node: Calling A Function514879 -Node: Variable Scope515994 -Node: Pass By Value/Reference517969 -Node: Return Statement521409 -Node: Dynamic Typing524390 -Node: Indirect Calls525125 -Node: Internationalization534810 -Node: I18N and L10N536236 -Node: Explaining gettext536922 -Ref: Explaining gettext-Footnote-1541988 -Ref: Explaining gettext-Footnote-2542172 -Node: Programmer i18n542337 -Node: Translator i18n546537 -Node: String Extraction547330 -Ref: String Extraction-Footnote-1548291 -Node: Printf Ordering548377 -Ref: Printf Ordering-Footnote-1551161 -Node: I18N Portability551225 -Ref: I18N Portability-Footnote-1553674 -Node: I18N Example553737 -Ref: I18N Example-Footnote-1556372 -Node: Gawk I18N556444 -Node: Advanced Features557061 -Node: Nondecimal Data558574 -Node: Array Sorting560157 -Node: Controlling Array Traversal560854 -Node: Array Sorting Functions569091 -Ref: Array Sorting Functions-Footnote-1572765 -Ref: Array Sorting Functions-Footnote-2572858 -Node: Two-way I/O573052 -Ref: Two-way I/O-Footnote-1578484 -Node: TCP/IP Networking578554 -Node: Profiling581398 -Node: Library Functions588872 -Ref: Library Functions-Footnote-1591879 -Node: Library Names592050 -Ref: Library Names-Footnote-1595521 -Ref: Library Names-Footnote-2595741 -Node: General Functions595827 -Node: Strtonum Function596780 -Node: Assert Function599710 -Node: Round Function603036 -Node: Cliff Random Function604579 -Node: Ordinal Functions605595 -Ref: Ordinal Functions-Footnote-1608665 -Ref: Ordinal Functions-Footnote-2608917 -Node: Join Function609126 -Ref: Join Function-Footnote-1610897 -Node: Gettimeofday Function611097 -Node: Data File Management614812 -Node: Filetrans Function615444 -Node: Rewind Function619583 -Node: File Checking620970 -Node: Empty Files622064 -Node: Ignoring Assigns624294 -Node: Getopt Function625847 -Ref: Getopt Function-Footnote-1637151 -Node: Passwd Functions637354 -Ref: Passwd Functions-Footnote-1646329 -Node: Group Functions646417 -Node: Walking Arrays654501 -Node: Sample Programs656070 -Node: Running Examples656735 -Node: Clones657463 -Node: Cut Program658687 -Node: Egrep Program668532 -Ref: Egrep Program-Footnote-1676305 -Node: Id Program676415 -Node: Split Program680031 -Ref: Split Program-Footnote-1683550 -Node: Tee Program683678 -Node: Uniq Program686481 -Node: Wc Program693910 -Ref: Wc Program-Footnote-1698176 -Ref: Wc Program-Footnote-2698376 -Node: Miscellaneous Programs698468 -Node: Dupword Program699656 -Node: Alarm Program701687 -Node: Translate Program706436 -Ref: Translate Program-Footnote-1710823 -Ref: Translate Program-Footnote-2711051 -Node: Labels Program711185 -Ref: Labels Program-Footnote-1714556 -Node: Word Sorting714640 -Node: History Sorting718524 -Node: Extract Program720363 -Ref: Extract Program-Footnote-1727846 -Node: Simple Sed727974 -Node: Igawk Program731036 -Ref: Igawk Program-Footnote-1746193 -Ref: Igawk Program-Footnote-2746394 -Node: Anagram Program746532 -Node: Signature Program749600 -Node: Debugger750700 -Node: Debugging751611 -Node: Debugging Concepts752024 -Node: Debugging Terms753880 -Node: Awk Debugging756503 -Node: Sample dgawk session757395 -Node: dgawk invocation757887 -Node: Finding The Bug759069 -Node: List of Debugger Commands765555 -Node: Breakpoint Control766866 -Node: Dgawk Execution Control770502 -Node: Viewing And Changing Data773853 -Node: Dgawk Stack777190 -Node: Dgawk Info778650 -Node: Miscellaneous Dgawk Commands782598 -Node: Readline Support788026 -Node: Dgawk Limitations788864 -Node: Language History791053 -Node: V7/SVR3.1792565 -Node: SVR4794886 -Node: POSIX796328 -Node: BTL797336 -Node: POSIX/GNU798070 -Node: Common Extensions803221 -Node: Ranges and Locales804328 -Ref: Ranges and Locales-Footnote-1808932 -Node: Contributors809153 -Node: Installation813415 -Node: Gawk Distribution814309 -Node: Getting814793 -Node: Extracting815619 -Node: Distribution contents817311 -Node: Unix Installation822533 -Node: Quick Installation823150 -Node: Additional Configuration Options825112 -Node: Configuration Philosophy826589 -Node: Non-Unix Installation828931 -Node: PC Installation829389 -Node: PC Binary Installation830688 -Node: PC Compiling832536 -Node: PC Testing835480 -Node: PC Using836656 -Node: Cygwin840841 -Node: MSYS841841 -Node: VMS Installation842355 -Node: VMS Compilation842958 -Ref: VMS Compilation-Footnote-1843965 -Node: VMS Installation Details844023 -Node: VMS Running845658 -Node: VMS Old Gawk847265 -Node: Bugs847739 -Node: Other Versions851591 -Node: Notes856872 -Node: Compatibility Mode857564 -Node: Additions858347 -Node: Accessing The Source859159 -Node: Adding Code860584 -Node: New Ports866551 -Node: Dynamic Extensions870664 -Node: Internals872040 -Node: Plugin License881143 -Node: Sample Library881777 -Node: Internal File Description882463 -Node: Internal File Ops886178 -Ref: Internal File Ops-Footnote-1890959 -Node: Using Internal File Ops891099 -Node: Future Extensions893476 -Node: Basic Concepts895980 -Node: Basic High Level896737 -Ref: Basic High Level-Footnote-1900772 -Node: Basic Data Typing900957 -Node: Floating Point Issues905482 -Node: String Conversion Precision906565 -Ref: String Conversion Precision-Footnote-1908265 -Node: Unexpected Results908374 -Node: POSIX Floating Point Problems910200 -Ref: POSIX Floating Point Problems-Footnote-1913905 -Node: Glossary913943 -Node: Copying938919 -Node: GNU Free Documentation License976476 -Node: Index1001613 +Node: Getline Summary228306 +Ref: table-getline-variants228649 +Node: Command line directories229505 +Node: Printing230130 +Node: Print231761 +Node: Print Examples233098 +Node: Output Separators235882 +Node: OFMT237642 +Node: Printf239000 +Node: Basic Printf239906 +Node: Control Letters241445 +Node: Format Modifiers245257 +Node: Printf Examples251266 +Node: Redirection253981 +Node: Special Files260965 +Node: Special FD261498 +Ref: Special FD-Footnote-1265123 +Node: Special Network265197 +Node: Special Caveats266047 +Node: Close Files And Pipes266843 +Ref: Close Files And Pipes-Footnote-1273866 +Ref: Close Files And Pipes-Footnote-2274014 +Node: Expressions274164 +Node: Values275296 +Node: Constants275972 +Node: Scalar Constants276652 +Ref: Scalar Constants-Footnote-1277511 +Node: Nondecimal-numbers277693 +Node: Regexp Constants280752 +Node: Using Constant Regexps281227 +Node: Variables284282 +Node: Using Variables284937 +Node: Assignment Options286661 +Node: Conversion288533 +Ref: table-locale-affects293909 +Ref: Conversion-Footnote-1294533 +Node: All Operators294642 +Node: Arithmetic Ops295272 +Node: Concatenation297777 +Ref: Concatenation-Footnote-1300570 +Node: Assignment Ops300690 +Ref: table-assign-ops305678 +Node: Increment Ops307086 +Node: Truth Values and Conditions310556 +Node: Truth Values311639 +Node: Typing and Comparison312688 +Node: Variable Typing313477 +Ref: Variable Typing-Footnote-1317374 +Node: Comparison Operators317496 +Ref: table-relational-ops317906 +Node: POSIX String Comparison321455 +Ref: POSIX String Comparison-Footnote-1322411 +Node: Boolean Ops322549 +Ref: Boolean Ops-Footnote-1326627 +Node: Conditional Exp326718 +Node: Function Calls328450 +Node: Precedence332044 +Node: Locales335713 +Node: Patterns and Actions336802 +Node: Pattern Overview337856 +Node: Regexp Patterns339525 +Node: Expression Patterns340068 +Node: Ranges343753 +Node: BEGIN/END346719 +Node: Using BEGIN/END347481 +Ref: Using BEGIN/END-Footnote-1350212 +Node: I/O And BEGIN/END350318 +Node: BEGINFILE/ENDFILE352600 +Node: Empty355493 +Node: Using Shell Variables355809 +Node: Action Overview358094 +Node: Statements360451 +Node: If Statement362305 +Node: While Statement363804 +Node: Do Statement365848 +Node: For Statement367004 +Node: Switch Statement370156 +Node: Break Statement372253 +Node: Continue Statement374243 +Node: Next Statement376036 +Node: Nextfile Statement378426 +Node: Exit Statement380971 +Node: Built-in Variables383387 +Node: User-modified384482 +Ref: User-modified-Footnote-1392508 +Node: Auto-set392570 +Ref: Auto-set-Footnote-1401861 +Node: ARGC and ARGV402066 +Node: Arrays405917 +Node: Array Basics407422 +Node: Array Intro408248 +Node: Reference to Elements412566 +Node: Assigning Elements414836 +Node: Array Example415327 +Node: Scanning an Array417059 +Node: Controlling Scanning419373 +Ref: Controlling Scanning-Footnote-1424306 +Node: Delete424622 +Ref: Delete-Footnote-1427057 +Node: Numeric Array Subscripts427114 +Node: Uninitialized Subscripts429297 +Node: Multi-dimensional430925 +Node: Multi-scanning434019 +Node: Arrays of Arrays435610 +Node: Functions440255 +Node: Built-in441077 +Node: Calling Built-in442155 +Node: Numeric Functions444143 +Ref: Numeric Functions-Footnote-1447975 +Ref: Numeric Functions-Footnote-2448332 +Ref: Numeric Functions-Footnote-3448380 +Node: String Functions448649 +Ref: String Functions-Footnote-1472146 +Ref: String Functions-Footnote-2472275 +Ref: String Functions-Footnote-3472523 +Node: Gory Details472610 +Ref: table-sub-escapes474289 +Ref: table-sub-posix-92475643 +Ref: table-sub-proposed476986 +Ref: table-posix-sub478336 +Ref: table-gensub-escapes479882 +Ref: Gory Details-Footnote-1481089 +Ref: Gory Details-Footnote-2481140 +Node: I/O Functions481291 +Ref: I/O Functions-Footnote-1487946 +Node: Time Functions488093 +Ref: Time Functions-Footnote-1498985 +Ref: Time Functions-Footnote-2499053 +Ref: Time Functions-Footnote-3499211 +Ref: Time Functions-Footnote-4499322 +Ref: Time Functions-Footnote-5499434 +Ref: Time Functions-Footnote-6499661 +Node: Bitwise Functions499927 +Ref: table-bitwise-ops500485 +Ref: Bitwise Functions-Footnote-1504645 +Node: Type Functions504829 +Node: I18N Functions505299 +Node: User-defined506926 +Node: Definition Syntax507730 +Ref: Definition Syntax-Footnote-1512640 +Node: Function Example512709 +Node: Function Caveats515303 +Node: Calling A Function515724 +Node: Variable Scope516839 +Node: Pass By Value/Reference518814 +Node: Return Statement522254 +Node: Dynamic Typing525235 +Node: Indirect Calls525970 +Node: Internationalization535655 +Node: I18N and L10N537081 +Node: Explaining gettext537767 +Ref: Explaining gettext-Footnote-1542833 +Ref: Explaining gettext-Footnote-2543017 +Node: Programmer i18n543182 +Node: Translator i18n547382 +Node: String Extraction548175 +Ref: String Extraction-Footnote-1549136 +Node: Printf Ordering549222 +Ref: Printf Ordering-Footnote-1552006 +Node: I18N Portability552070 +Ref: I18N Portability-Footnote-1554519 +Node: I18N Example554582 +Ref: I18N Example-Footnote-1557217 +Node: Gawk I18N557289 +Node: Advanced Features557906 +Node: Nondecimal Data559419 +Node: Array Sorting561002 +Node: Controlling Array Traversal561699 +Node: Array Sorting Functions569936 +Ref: Array Sorting Functions-Footnote-1573610 +Ref: Array Sorting Functions-Footnote-2573703 +Node: Two-way I/O573897 +Ref: Two-way I/O-Footnote-1579329 +Node: TCP/IP Networking579399 +Node: Profiling582243 +Node: Library Functions589717 +Ref: Library Functions-Footnote-1592724 +Node: Library Names592895 +Ref: Library Names-Footnote-1596366 +Ref: Library Names-Footnote-2596586 +Node: General Functions596672 +Node: Strtonum Function597625 +Node: Assert Function600555 +Node: Round Function603881 +Node: Cliff Random Function605424 +Node: Ordinal Functions606440 +Ref: Ordinal Functions-Footnote-1609510 +Ref: Ordinal Functions-Footnote-2609762 +Node: Join Function609971 +Ref: Join Function-Footnote-1611742 +Node: Gettimeofday Function611942 +Node: Data File Management615657 +Node: Filetrans Function616289 +Node: Rewind Function620428 +Node: File Checking621815 +Node: Empty Files622909 +Node: Ignoring Assigns625139 +Node: Getopt Function626692 +Ref: Getopt Function-Footnote-1637996 +Node: Passwd Functions638199 +Ref: Passwd Functions-Footnote-1647174 +Node: Group Functions647262 +Node: Walking Arrays655346 +Node: Sample Programs656915 +Node: Running Examples657580 +Node: Clones658308 +Node: Cut Program659532 +Node: Egrep Program669377 +Ref: Egrep Program-Footnote-1677150 +Node: Id Program677260 +Node: Split Program680876 +Ref: Split Program-Footnote-1684395 +Node: Tee Program684523 +Node: Uniq Program687326 +Node: Wc Program694755 +Ref: Wc Program-Footnote-1699021 +Ref: Wc Program-Footnote-2699221 +Node: Miscellaneous Programs699313 +Node: Dupword Program700501 +Node: Alarm Program702532 +Node: Translate Program707281 +Ref: Translate Program-Footnote-1711668 +Ref: Translate Program-Footnote-2711896 +Node: Labels Program712030 +Ref: Labels Program-Footnote-1715401 +Node: Word Sorting715485 +Node: History Sorting719369 +Node: Extract Program721208 +Ref: Extract Program-Footnote-1728691 +Node: Simple Sed728819 +Node: Igawk Program731881 +Ref: Igawk Program-Footnote-1747038 +Ref: Igawk Program-Footnote-2747239 +Node: Anagram Program747377 +Node: Signature Program750445 +Node: Debugger751545 +Node: Debugging752456 +Node: Debugging Concepts752869 +Node: Debugging Terms754725 +Node: Awk Debugging757348 +Node: Sample dgawk session758240 +Node: dgawk invocation758732 +Node: Finding The Bug759914 +Node: List of Debugger Commands766400 +Node: Breakpoint Control767711 +Node: Dgawk Execution Control771347 +Node: Viewing And Changing Data774698 +Node: Dgawk Stack778035 +Node: Dgawk Info779495 +Node: Miscellaneous Dgawk Commands783443 +Node: Readline Support788871 +Node: Dgawk Limitations789709 +Node: Language History791898 +Node: V7/SVR3.1793410 +Node: SVR4795731 +Node: POSIX797173 +Node: BTL798181 +Node: POSIX/GNU798915 +Node: Common Extensions804066 +Node: Ranges and Locales805173 +Ref: Ranges and Locales-Footnote-1809777 +Node: Contributors809998 +Node: Installation814260 +Node: Gawk Distribution815154 +Node: Getting815638 +Node: Extracting816464 +Node: Distribution contents818156 +Node: Unix Installation823378 +Node: Quick Installation823995 +Node: Additional Configuration Options825957 +Node: Configuration Philosophy827434 +Node: Non-Unix Installation829776 +Node: PC Installation830234 +Node: PC Binary Installation831533 +Node: PC Compiling833381 +Node: PC Testing836325 +Node: PC Using837501 +Node: Cygwin841686 +Node: MSYS842686 +Node: VMS Installation843200 +Node: VMS Compilation843803 +Ref: VMS Compilation-Footnote-1844810 +Node: VMS Installation Details844868 +Node: VMS Running846503 +Node: VMS Old Gawk848110 +Node: Bugs848584 +Node: Other Versions852436 +Node: Notes857717 +Node: Compatibility Mode858409 +Node: Additions859192 +Node: Accessing The Source860004 +Node: Adding Code861429 +Node: New Ports867396 +Node: Dynamic Extensions871509 +Node: Internals872885 +Node: Plugin License881988 +Node: Sample Library882622 +Node: Internal File Description883308 +Node: Internal File Ops887023 +Ref: Internal File Ops-Footnote-1891804 +Node: Using Internal File Ops891944 +Node: Future Extensions894321 +Node: Basic Concepts896825 +Node: Basic High Level897582 +Ref: Basic High Level-Footnote-1901617 +Node: Basic Data Typing901802 +Node: Floating Point Issues906327 +Node: String Conversion Precision907410 +Ref: String Conversion Precision-Footnote-1909110 +Node: Unexpected Results909219 +Node: POSIX Floating Point Problems911045 +Ref: POSIX Floating Point Problems-Footnote-1914750 +Node: Glossary914788 +Node: Copying939764 +Node: GNU Free Documentation License977321 +Node: Index1002458 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index ba5ffa30..fb17b716 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -7171,6 +7171,34 @@ trying to accomplish. It is worth noting that those variants which do not use redirection can cause @code{FILENAME} to be updated if they cause @command{awk} to start reading a new input file. + +@item +If the variable being assigned is an expression with side effects, +different versions of @command{awk} behave differently upon encountering +end-of-file. Some versions don't evaluate the expression; many versions +(including @command{gawk}) do. Here is an example, due to Duncan Moore: + +@ignore +Date: Sun, 01 Apr 2012 11:49:33 +0100 +From: Duncan Moore <duncan.moore@@gmx.com> +@end ignore + +@example +BEGIN @{ + system("echo 1 > f") + while ((getline a[++c] < "f") > 0) @{ @} + print c +@} +@end example + +@noindent +Here, the side effect is the @samp{++c}. Is @code{c} incremented if +end of file is encountered, before the element in @code{a} is assigned? + +@command{gawk} treats @code{getline} like a function call, and evaluates +the expression @samp{a[++c]} before attempting to read from @file{f}. +Other versions of @command{awk} only evaluate the expression once they +know that there is a string value to be assigned. Caveat Emptor. @end itemize @node Getline Summary diff --git a/test/ChangeLog b/test/ChangeLog index 272e7cf2..bb26c185 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2012-07-13 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (getline5): New test. + * getline5.awk, getline5.ok: New files. + 2012-06-19 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (charasbytes): New test. diff --git a/test/Makefile.am b/test/Makefile.am index 43cc8f9c..967a20c4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -298,6 +298,8 @@ EXTRA_DIST = \ getline4.awk \ getline4.in \ getline4.ok \ + getline5.awk \ + getline5.ok \ getlnbuf.awk \ getlnbuf.in \ getlnbuf.ok \ @@ -804,7 +806,7 @@ BASIC_TESTS = \ fcall_exit fcall_exit2 fldchg fldchgnf fnamedat fnarray fnarray2 \ fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fsrs fsspcoln \ fstabplus funsemnl funsmnam funstack \ - getline getline2 getline3 getline4 getlnbuf getnr2tb getnr2tm \ + getline getline2 getline3 getline4 getline5 getlnbuf getnr2tb getnr2tm \ gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 gsubtst6 \ gsubtst7 gsubtst8 \ hex hsprint \ diff --git a/test/Makefile.in b/test/Makefile.in index 0e4cc757..be567702 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -503,6 +503,8 @@ EXTRA_DIST = \ getline4.awk \ getline4.in \ getline4.ok \ + getline5.awk \ + getline5.ok \ getlnbuf.awk \ getlnbuf.in \ getlnbuf.ok \ @@ -1009,7 +1011,7 @@ BASIC_TESTS = \ fcall_exit fcall_exit2 fldchg fldchgnf fnamedat fnarray fnarray2 \ fnaryscl fnasgnm fnmisc fordel forref forsimp fsbs fsrs fsspcoln \ fstabplus funsemnl funsmnam funstack \ - getline getline2 getline3 getline4 getlnbuf getnr2tb getnr2tm \ + getline getline2 getline3 getline4 getline5 getlnbuf getnr2tb getnr2tm \ gsubasgn gsubtest gsubtst2 gsubtst3 gsubtst4 gsubtst5 gsubtst6 \ gsubtst7 gsubtst8 \ hex hsprint \ @@ -2168,6 +2170,11 @@ getline4: @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +getline5: + @echo getline5 + @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + getnr2tb: @echo getnr2tb @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 34a0aaa6..1b58d5b4 100644 --- a/test/Maketests +++ b/test/Maketests @@ -320,6 +320,11 @@ getline4: @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ +getline5: + @echo getline5 + @AWKPATH=$(srcdir) $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@ + getnr2tb: @echo getnr2tb @AWKPATH=$(srcdir) $(AWK) -f $@.awk < $(srcdir)/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/getline5.awk b/test/getline5.awk new file mode 100644 index 00000000..4757bcfe --- /dev/null +++ b/test/getline5.awk @@ -0,0 +1,35 @@ +# Message-ID: <4F7832BD.9030709@gmx.com> +# Date: Sun, 01 Apr 2012 11:49:33 +0100 +# From: Duncan Moore <duncan.moore@gmx.com> +# To: "bug-gawk@gnu.org" <bug-gawk@gnu.org> +# Subject: [bug-gawk] getline difference from gawk versions >=4.0.0 +# +# Hi +# +# b.awk: +# +# BEGIN { +# system("echo 1 > f") +# while ((getline a[++c] < "f") > 0) {} +# print c +# } +# +# gawk -f b.awk +# +# Prior to gawk 4.0.0 this outputs: +# +# 1 +# +# For 4.0.0 and 4.0.1 it outputs: +# +# 2 +# +# Regards +# Duncan Moore + +BEGIN { + system("echo 1 > f") + while ((getline a[++c] < "f") > 0) {} + print c + system("rm -f f") +} diff --git a/test/getline5.ok b/test/getline5.ok new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/test/getline5.ok @@ -0,0 +1 @@ +2 |