Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^6: porting C code to Perl

by RonW (Parson)
on Oct 25, 2017 at 20:47 UTC ( #1202036=note: print w/replies, xml ) Need Help??


in reply to Re^5: porting C code to Perl
in thread porting C code to Perl

As you discovered,

int nines, predigit = 0;

is not the same as

int nines = 0; int predigit = 0;

I'm surprised int nines, predigit = 0; is even valid C syntax.1

However, nines, predigit = 0; is valid C syntax, but treats nines and predigit = 0 as 2 separate expressions. nines is evaluated in void context (so, the warning you got), while 0 is evaluated in an integer context and then assigned to predigit (effectively, predigit is in lvalue context).

An alternate syntax that would have zero'd both is nines = predigit = 0; which may be what the author intended to write (but he should have gotten the warning).

---

1 Note that in Perl, my ($nines, $predigit) = 0; will init $nines to 0 and leave $predigit undefined. Also, it doesn't give a warning.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1202036]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2019-05-27 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (156 votes). Check out past polls.

    Notices?