Cyan4973 / FiniteStateEntropy

New generation entropy codecs : Finite State Entropy and Huff0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

superflous semicolon?

DennisOSRM opened this issue · comments

It works as intended.

This line must be read as :
while (!normalizedCounter[charnum++]);
charnum--;

That is, 2 separate operations.

The first one is almost equivalent to :
while (!normalizedCounter[charnum]) charnum++;

Now the problem is, when normalizedCounter>0, it stops, but nonetheless increments charnum.
So charnum is one too large.
This is corrected by the second line : charnum--;

So it works as intended.
However, retrospectively, it seems this line would be easier to read, and perform the same :
while (!normalizedCounter[charnum]) charnum++;

So maybe it would be a good idea to change it.

Right, it would at least silence the compiler:

$ clang -O3 -I.. -std=c99 -Wall -W -Wundef bench.c commandline.c fileio.c lz4hce.c xxhash.c fseDist.c fse2t.c zlibh.c ../fse.c -o fse
../fse.c:185:50: warning: while loop has empty body [-Wempty-body]
            while (!normalizedCounter[charnum++]); charnum--;
                                                 ^
../fse.c:185:50: note: put the semicolon on a separate line to silence this warning
1 warning generated.

The modification has been uploaded into the beta branch.

awesome, thanks