bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: gawk printf format problem with negative numbers


From: Shaffer, Kenneth
Subject: RE: gawk printf format problem with negative numbers
Date: Tue, 28 Oct 2003 13:44:18 -0500

I didn't do any compiles.  I got it from the cygwin.com site, http://www.cygwin.com and downloaded the latest binary packages offered. I'm running Windows 2000. I've just downloaded the source to build myself and compiled with GAWKDEBUG and YYDEBUG flags set and received the following:

shaffek>echo |./gawk -D '{n = -1234; printf("0x%x\n",n+0)}'
Starting parse
Entering state 0
Reading a token: Next token is token '{' ()
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0
Entering state 4
Reducing stack by rule 2 (line 177), -> program
Stack now 0 4
Entering state 7
Next token is token '{' ()
Reducing stack by rule 8 (line 226), -> pattern
Stack now 0 4 7
Entering state 29
Next token is token '{' ()
Shifting token '{', Entering state 60
Reading a token: Next token is token NAME ()
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0 4 7 29 60
Entering state 115
Reducing stack by rule 147 (line 954), '{' opt_nls -> l_brace
Stack now 0 4 7 29
Entering state 65
Reducing stack by rule 25 (line 333), -> statements
Stack now 0 4 7 29 65
Entering state 116
Next token is token NAME ()
Shifting token NAME, Entering state 10
Reading a token: Next token is token ASSIGN ()
Reducing stack by rule 144 (line 933), NAME -> variable
Stack now 0 4 7 29 65 116
Entering state 38
Next token is token ASSIGN ()
Shifting token ASSIGN, Entering state 89
Reducing stack by rule 106 (line 800), ASSIGN -> assign_operator
Stack now 0 4 7 29 65 116 38
Entering state 93
Reading a token: Next token is token '-' ()
Shifting token '-', Entering state 23
Reading a token: Next token is token YNUMBER ()
Shifting token YNUMBER, Entering state 11
Reducing stack by rule 138 (line 902), YNUMBER -> non_post_simp_exp
Stack now 0 4 7 29 65 116 38 93 23
Entering state 37
Reducing stack by rule 118 (line 840), non_post_simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 38 93 23
Entering state 52
Reading a token: Next token is token ';' ()
Reducing stack by rule 140 (line 907), '-' simp_exp -> non_post_simp_exp
Stack now 0 4 7 29 65 116 38 93
Entering state 37
Reducing stack by rule 118 (line 840), non_post_simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 38 93
Entering state 36
Next token is token ';' ()
Reducing stack by rule 116 (line 833), simp_exp -> common_exp
Stack now 0 4 7 29 65 116 38 93
Entering state 35
Next token is token ';' ()
Reducing stack by rule 105 (line 795), common_exp -> exp
Stack now 0 4 7 29 65 116 38 93
Entering state 134
Next token is token ';' ()
Reducing stack by rule 98 (line 769), variable assign_operator exp -> exp
Stack now 0 4 7 29 65 116
Entering state 166
Next token is token ';' ()
Reducing stack by rule 52 (line 543), exp -> simple_stmt
Stack now 0 4 7 29 65 116
Entering state 163
Next token is token ';' ()
Shifting token ';', Entering state 61
Reducing stack by rule 152 (line 971), ';' -> semi
Stack now 0 4 7 29 65 116 163
Entering state 66
Reading a token: Next token is token LEX_PRINTF ()
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0 4 7 29 65 116 163 66
Entering state 117
Reducing stack by rule 29 (line 358), semi opt_nls -> statement_term
Stack now 0 4 7 29 65 116 163
Entering state 192
Reducing stack by rule 46 (line 469), simple_stmt statement_term -> statement
Stack now 0 4 7 29 65 116
Entering state 162
Reducing stack by rule 26 (line 334), statements statement -> statements
Stack now 0 4 7 29 65
Entering state 116
Next token is token LEX_PRINTF ()
Shifting token LEX_PRINTF, Entering state 157
Reducing stack by rule 67 (line 655), LEX_PRINTF -> print
Stack now 0 4 7 29 65 116
Entering state 164
Reducing stack by rule 47 (line 481), -> @4
Stack now 0 4 7 29 65 116 164
Entering state 193
Reading a token: Next token is token '(' ()
Shifting token '(', Entering state 213
Reading a token: Next token is token YSTRING ()
Shifting token YSTRING, Entering state 12
Reducing stack by rule 139 (line 904), YSTRING -> non_post_simp_exp
Stack now 0 4 7 29 65 116 164 193 213
Entering state 37
Reducing stack by rule 118 (line 840), non_post_simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 164 193 213
Entering state 36
Reading a token: Next token is token ',' ()
Reducing stack by rule 116 (line 833), simp_exp -> common_exp
Stack now 0 4 7 29 65 116 164 193 213
Entering state 35
Next token is token ',' ()
Reducing stack by rule 105 (line 795), common_exp -> exp
Stack now 0 4 7 29 65 116 164 193 213
Entering state 230
Next token is token ',' ()
Shifting token ',', Entering state 110
Reading a token: Next token is token NAME ()
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0 4 7 29 65 116 164 193 213 230 110
Entering state 142
Reducing stack by rule 154 (line 978), ',' opt_nls -> comma
Stack now 0 4 7 29 65 116 164 193 213 230
Entering state 240
Next token is token NAME ()
Shifting token NAME, Entering state 10
Reading a token: Next token is token '+' ()
Reducing stack by rule 144 (line 933), NAME -> variable
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 38
Next token is token '+' ()
Reducing stack by rule 135 (line 897), variable -> non_post_simp_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 37
Reducing stack by rule 118 (line 840), non_post_simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 36
Next token is token '+' ()
Shifting token '+', Entering state 82
Reading a token: Next token is token YNUMBER ()
Shifting token YNUMBER, Entering state 11
Reducing stack by rule 138 (line 902), YNUMBER -> non_post_simp_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240 36 82
Entering state 37
Reducing stack by rule 118 (line 840), non_post_simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240 36 82
Entering state 127
Reading a token: Next token is token ')' ()
Reducing stack by rule 123 (line 850), simp_exp '+' simp_exp -> simp_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 36
Next token is token ')' ()
Reducing stack by rule 116 (line 833), simp_exp -> common_exp
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 35
Next token is token ')' ()
Reducing stack by rule 105 (line 795), common_exp -> exp
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 96
Next token is token ')' ()
Reducing stack by rule 92 (line 750), exp -> expression_list
Stack now 0 4 7 29 65 116 164 193 213 230 240
Entering state 249
Next token is token ')' ()
Shifting token ')', Entering state 111
Reducing stack by rule 149 (line 962), ')' -> r_paren
Stack now 0 4 7 29 65 116 164 193 213 230 240 249
Entering state 258
Reducing stack by rule 69 (line 664), '(' exp comma expression_list r_paren -> print_expression_list
Stack now 0 4 7 29 65 116 164 193
Entering state 214
Reading a token: Next token is token NEWLINE ()
Reducing stack by rule 70 (line 670), -> output_redir
Stack now 0 4 7 29 65 116 164 193 214
Entering state 232
Reducing stack by rule 48 (line 481), print @4 print_expression_list output_redir -> simple_stmt
Stack now 0 4 7 29 65 116
Entering state 163
Next token is token NEWLINE ()
Shifting token NEWLINE, Entering state 1
Reducing stack by rule 75 (line 698), NEWLINE -> nls
Stack now 0 4 7 29 65 116 163
Entering state 64
Reading a token: Next token is token '}' ()
Reducing stack by rule 28 (line 357), nls -> statement_term
Stack now 0 4 7 29 65 116 163
Entering state 192
Reducing stack by rule 46 (line 469), simple_stmt statement_term -> statement
Stack now 0 4 7 29 65 116
Entering state 162
Reducing stack by rule 26 (line 334), statements statement -> statements
Stack now 0 4 7 29 65
Entering state 116
Next token is token '}' ()
Shifting token '}', Entering state 161
Reading a token: Next token is token NEWLINE ()
Shifting token NEWLINE, Entering state 1
Reducing stack by rule 75 (line 698), NEWLINE -> nls
Stack now 0 4 7 29 65 116 161
Entering state 3
Reading a token: Now at end of input.
Reducing stack by rule 78 (line 704), nls -> opt_nls
Stack now 0 4 7 29 65 116 161
Entering state 191
Reducing stack by rule 148 (line 958), '}' opt_nls -> r_brace
Stack now 0 4 7 29 65 116
Entering state 168
Now at end of input.
Reducing stack by rule 150 (line 965), -> opt_semi
Stack now 0 4 7 29 65 116 168
Entering state 195
Now at end of input.
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0 4 7 29 65 116 168 195
Entering state 217
Reducing stack by rule 13 (line 256), l_brace statements r_brace opt_semi opt_nls -> action
Stack now 0 4 7 29
Entering state 62
Reducing stack by rule 5 (line 196), pattern action -> rule
Stack now 0 4 7
Entering state 28
Reducing stack by rule 3 (line 179), program rule -> program
Stack now 0 4
Entering state 7
Now at end of input.
Reducing stack by rule 77 (line 702), -> opt_nls
Stack now 0 4 7
Entering state 33
Reducing stack by rule 1 (line 171), opt_nls program opt_nls -> start
Stack now 0
Entering state 2
Now at end of input.
0x-1234
/usr/src/gawk-3.1.3-3
shaffek>

--
Ken Shaffer
Staff Software Engineer
770-236-3421
address@hidden
 
 
> I expected the output of a negative 1234 in hex to look like 0xfffffb2e:

> > echo |gawk '{n = -1234; printf("0x%x\n",n+0)}'
> 0x-1234
>
> > gawk --version
> GNU Awk 3.1.3

> running under cygwin for the PC.

        Fascinating, Captain.
                --- Mr. Spock

I don't see this on my system, Redhat 8 Linux:

        $ echo | gawk-3.1.3 '{n = -1234; printf("0x%x\n",n+0)}'
        0xfffffffffffffb2e
        $ gawk-3.1.3 'BEGIN {n = -1234; printf("0x%x\n",n+0)}'
        0xfffffffffffffb2e

I get the same behavior in my development version as well.

What system and compiler are you using?  Are you able to track
this down?  If not, then maybe we can arrange offline for me
to have ssh access to your system to debug it.

Thanks,

Arnold



- - - - - - - Appended by Scientific-Atlanta, Inc. - - - - - - -
This e-mail and any attachments may contain information which is confidential, proprietary, privileged or otherwise protected by law. The information is solely intended for the named addressee (or a person responsible for delivering it to the addressee). If you are not the intended recipient of this message, you are not authorized to read, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]