chai2010 / webp

WebP decoder and encoder for Go (Zero Dependencies).
http://godoc.org/github.com/chai2010/webp
BSD 3-Clause "New" or "Revised" License
539 stars 90 forks source link

Error compiling: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' #35

Closed ainsleyclark closed 2 years ago

ainsleyclark commented 3 years ago

Hi there,

Thanks for the great package. When installing/building I am receiving an error:

../../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)? [-Wxor-used-as-pow]
../../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning

Not sure how to go about this?

Many thanks.

alinz commented 3 years ago

Hello @ainsleyclark this is not an error. This is just a warning hint from compiler for make the code a little bit faster. If you take a look at this file, the code tries to calculate 2 to the power of ALPHA_OFFSET. There is a better and faster way of doing this by using bitwise operator, like shift. Both 2 ^ ALPHA_OFFSET and 1 << ALPHA_OFFSET has the same output but the second option is faster.

I think, for readability, 2 ^ ALPHA_OFFSET is much more understandable than 1 << ALPHA_OFFSET

So the bottom line is, you can safely ignore this warning.

zhangi commented 3 years ago

"Both 2 ^ ALPHA_OFFSET and 1 << ALPHA_OFFSET has the same output but the second option is faster." -> As the compiler warning tells, they are not the same at all, 2 ^ ALPHA_OFFSET is a XOR operator in c, it does not mean 2 to the power of ALPHA_OFFSET

multita commented 3 years ago

大佬修一下吧

ruanlianjun commented 2 years ago

can you fix it

hexcowboy commented 2 years ago

Is there a way to silence this warning?

rockstaedt commented 1 year ago

There is a hint in the console:

picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning