Comment by layer8 2 months ago Java has char as an unsigned 16-bit integer type. They should have made byte unsigned as well. 8 comments layer8 Reply pjmlp 2 months ago Usually you don't do arithmetic with char in Java, this isn't C culture of anything goes. uecker 2 months ago It is not even possible to do arithmetic on char in C. pjmlp 2 months ago #include <stdio.h> unsigned int pack_rgb(unsigned char r, unsigned char g, unsigned char b) { return (r << 16) | (g << 8) | b; } unsigned int pack_rgb_arith(unsigned char r, unsigned char g, unsigned char b) { return (r * 65536) + (g * 256) + b; } int main(void) { printf("The color value of (246, 176, 223) is %d\n", pack_rgb(246, 176, 223)); printf("The color value of (246, 176, 223) is %d\n", pack_rgb_arith(246, 176, 223)); } Compiler Explorer link, https://godbolt.org/z/3jExdaTT9I would expect a better comment from someone working on the standard. 2 replies → layer8 2 months ago There’s nothing preventing you from doing so. pjmlp 2 months ago I did not say otherwise, I said the culture is not the same towards safety.
pjmlp 2 months ago Usually you don't do arithmetic with char in Java, this isn't C culture of anything goes. uecker 2 months ago It is not even possible to do arithmetic on char in C. pjmlp 2 months ago #include <stdio.h> unsigned int pack_rgb(unsigned char r, unsigned char g, unsigned char b) { return (r << 16) | (g << 8) | b; } unsigned int pack_rgb_arith(unsigned char r, unsigned char g, unsigned char b) { return (r * 65536) + (g * 256) + b; } int main(void) { printf("The color value of (246, 176, 223) is %d\n", pack_rgb(246, 176, 223)); printf("The color value of (246, 176, 223) is %d\n", pack_rgb_arith(246, 176, 223)); } Compiler Explorer link, https://godbolt.org/z/3jExdaTT9I would expect a better comment from someone working on the standard. 2 replies → layer8 2 months ago There’s nothing preventing you from doing so. pjmlp 2 months ago I did not say otherwise, I said the culture is not the same towards safety.
uecker 2 months ago It is not even possible to do arithmetic on char in C. pjmlp 2 months ago #include <stdio.h> unsigned int pack_rgb(unsigned char r, unsigned char g, unsigned char b) { return (r << 16) | (g << 8) | b; } unsigned int pack_rgb_arith(unsigned char r, unsigned char g, unsigned char b) { return (r * 65536) + (g * 256) + b; } int main(void) { printf("The color value of (246, 176, 223) is %d\n", pack_rgb(246, 176, 223)); printf("The color value of (246, 176, 223) is %d\n", pack_rgb_arith(246, 176, 223)); } Compiler Explorer link, https://godbolt.org/z/3jExdaTT9I would expect a better comment from someone working on the standard. 2 replies →
pjmlp 2 months ago #include <stdio.h> unsigned int pack_rgb(unsigned char r, unsigned char g, unsigned char b) { return (r << 16) | (g << 8) | b; } unsigned int pack_rgb_arith(unsigned char r, unsigned char g, unsigned char b) { return (r * 65536) + (g * 256) + b; } int main(void) { printf("The color value of (246, 176, 223) is %d\n", pack_rgb(246, 176, 223)); printf("The color value of (246, 176, 223) is %d\n", pack_rgb_arith(246, 176, 223)); } Compiler Explorer link, https://godbolt.org/z/3jExdaTT9I would expect a better comment from someone working on the standard. 2 replies →
layer8 2 months ago There’s nothing preventing you from doing so. pjmlp 2 months ago I did not say otherwise, I said the culture is not the same towards safety.
Usually you don't do arithmetic with char in Java, this isn't C culture of anything goes.
It is not even possible to do arithmetic on char in C.
Compiler Explorer link, https://godbolt.org/z/3jExdaTT9
I would expect a better comment from someone working on the standard.
2 replies →
There’s nothing preventing you from doing so.
I did not say otherwise, I said the culture is not the same towards safety.