On Thu, Jan 24, 2019 at 12:14 PM zyx <z...@gmx.us> wrote:

> On Wed, 2019-01-23 at 20:09 +0100, Michal Sudolsky wrote:
> > I am tempted to note that -1 is stored in 8-bit integer in exactly
> > same way as 0xFF.
>
>         Hi,
> I used the code below with gcc 8.1.1 with this result (the result will
> make sense when the code is read):
>
>    [0] is -1; same:0/1/0 as signed:-1/255 as unsigned:4294967295/255
> switch match: s:1 u:0
>    [1] is 0; same:1/1/1 as signed:0/0 as unsigned:0/0 switch match: s:1 u:1
>    [2] is 1; same:1/1/1 as signed:1/1 as unsigned:1/1 switch match: s:1 u:1
>    [3] is 255; same:0/0/1 as signed:-1/255 as unsigned:4294967295/255
> switch match: s:0 u:1
>
> what it should write is to have the 'same' triple all ones in at least
> one column, not any of them zeros. You can see that 0xff and -1 are not
> the same when it comes to comparison, either with a real enum value or
> with signed and unsigned integers. I believe (according to my
> experience) that enums are like *signed* integers. Thus one might be
> careful what replacement type is used and which values will be assigned
> to it.
>

Unsigned char is zero-extended and signed char is sign-extended for
comparisons in your code sample. What would be seen from switch is that
when is stored either enMinusOne or enFF in n_int8 then it will be always
equal to enMinusOne and when stored in n_uint8 then enFF. So if there would
be None=-1 or Unknown=0xFF stored in 8-bit integer then later it cannot be
examined which one it was.



>
> The change mabri committed doesn't fix anything to upstream, it fixes a
> thing only to Francesco's private (and modified) checkout. The change
> also doesn't break anything upstream. Unless, some time later, someone
> decides to make Unknown -1 or anything like that. Then, hopefully, the
> compiler will claim something, thus it'll be noticed.
>         Bye,
>         zyx
>
> The used code follows. It generates compiler warnings with the switch-
> es, which is for good when looking for mistakes:
> ----------------------------------------------------
> /* g++ test.cpp -o test && ./test */
>
> #include <stdio.h>
>
> typedef enum {
>         enMinusOne = -1,
>         enZero = 0,
>         enOne = 1,
>         enFF = 0xFF
> } EN;
>
> int
> main (void)
> {
>         signed char n_int8;
>         unsigned char n_uint8;
>         bool smatch, umatch;
>         int ii;
>         EN ens[4] = { enMinusOne, enZero, enOne, enFF };
>
>         for (ii = 0; ii < 4; ii++) {
>                 n_int8 = ens[ii];
>                 n_uint8 = ens[ii];
>
>                 #define test_switch(_val,_res) \
>                         switch (_val) { \
>                         case enMinusOne: _res = ii == 0; break; \
>                         case enZero: _res = ii == 1; break; \
>                         case enOne: _res = ii == 2; break; \
>                         case enFF: _res = ii == 3; break; \
>                         default: _res = false; break; \
>                         }
>
>                 test_switch (n_int8, smatch);
>                 test_switch (n_uint8, umatch);
>
>                 #undef test_switch
>
>                 printf ("[%d] is %d; same:%d/%d/%d as signed:%d/%d as
> unsigned:%u/%u switch match: s:%d u:%d\n", ii, ens[ii],
>                         n_int8 == n_uint8, n_int8 == ens[ii], n_uint8 ==
> ens[ii],
>                         n_int8, n_uint8, n_int8, n_uint8,
>                         smatch, umatch);
>         }
>
>         return 0;
> }
>
>
>
>
> _______________________________________________
> Podofo-users mailing list
> Podofo-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/podofo-users
>
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to