File: strnum1.awk

package info (click to toggle)
goawk 1.29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 10,560 kB
  • sloc: awk: 3,060; yacc: 198; fortran: 189; python: 131; sh: 58; makefile: 12
file content (35 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Date: Tue, 04 Jul 2006 21:06:14 +0200 (MEST)
# From: Heiner Marxen <Heiner.Marxen@DrB.Insel.DE>
# Subject: conversion error
# To: bug-gawk@gnu.org
# Message-id: <200607041906.k64J6Eqa019360@drb9.drb.insel.de>
# 
# Hello,
# 
# The following awk script fails for gawk 3.1.4 and 3.1.5.
# Older versions did not do this, but I cannot say, how old they were.
# 
BEGIN {
    if( 0 ) {		#ok
	t = "8"
    }else {		#fails
	t = ""
	t = t "8"
    }
    printf("8  = %d\n", 0+t)	# ok without this line
    t = t "8"			# does not invalidate numeric interpretation
    printf("88 = %s\n", 0+t)
    ## The above prints "88 = 8" with gawk 3.1.4 and 3.1.5
}
# 
# 
# The following one-liner already exhibits the bug:
# 
# gawk 'BEGIN{t=""; t=t "8";printf("8=%d\n", 0+t);t=t "8";printf("88=%s\n", 0+t)}'
# 
# 
# Preliminary observation: under somewhat strange conditions a variable
# does retain its numeric interpretation although something is appended to it.
# -- 
# Heiner Marxen				http://www.drb.insel.de/~heiner/
#