Help request for debugging ICS

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Help request for debugging ICS

Post by hgm »

petero2 wrote:
hgm wrote:Hmm, when I remove the & from &t->name, all the non-sensical warnings and their duplicats disappear. Indeed t->name is an array, which is an address, and I have no idea how you could take the address of an address. Seems to me that this should be an error, rather than a warning. It surely confused the compiler, making it completely lose track of the type of other, unrelated variables.
There is a good explanation here: http://stackoverflow.com/questions/2528 ... value-in-c
OK, great. So the &t->name is not really an error, and I don't have to be afraid the ICS will crash because of it. And the type of &t->name is indeed the char (*)[100] mentioned in the spurious warning.

The compiler still seems to go completely haywire on this, however, claiming the argument of strlen (which is want, and not &t->name) has this type. So I can only cross my fingers in the hope it has compiled it as it should...
petero2
Posts: 690
Joined: Mon Apr 19, 2010 7:07 pm
Location: Sweden
Full name: Peter Osterlund

Re: Help request for debugging ICS

Post by petero2 »

hgm wrote:The compiler still seems to go completely haywire on this, however, claiming the argument of strlen (which is want, and not &t->name) has this type. So I can only cross my fingers in the hope it has compiled it as it should...
I see this too using gcc 6.3.1 in fedora 24. I think the compiler is working fine, but there are some scary macro definitions involved, presumably to optimize the cases where some of the arguments are known at compile time:

Code: Select all

# define strncmp(s1, s2, n) \
  (__extension__ (__builtin_constant_p &#40;s1&#41; && strlen &#40;s1&#41; < (&#40;size_t&#41; &#40;n&#41;)   \
                  ? strcmp (&#40;s1&#41;, &#40;s2&#41;)                                       \
                  &#58; (__builtin_constant_p &#40;s2&#41; && strlen &#40;s2&#41; < (&#40;size_t&#41; &#40;n&#41;)\
                     ? strcmp (&#40;s1&#41;, &#40;s2&#41;)                                    \
                     &#58; __strncmp_g (&#40;s1&#41;, &#40;s2&#41;, &#40;n&#41;))))
strcmp is even worse:

Code: Select all

# define strcmp&#40;s1, s2&#41; \
  (__extension__ (__builtin_constant_p &#40;s1&#41; && __builtin_constant_p &#40;s2&#41;      \
                  && &#40;sizeof (&#40;s1&#41;&#91;0&#93;) != 1 || strlen &#40;s1&#41; >= 4&#41;              \
                  && &#40;sizeof (&#40;s2&#41;&#91;0&#93;) != 1 || strlen &#40;s2&#41; >= 4&#41;              \
                  ? memcmp (&#40;const char *) &#40;s1&#41;, &#40;const char *) &#40;s2&#41;,         \
                            &#40;strlen &#40;s1&#41; < strlen &#40;s2&#41;                        \
                             ? strlen &#40;s1&#41; &#58; strlen &#40;s2&#41;) + 1&#41;                \
                  &#58; (__builtin_constant_p &#40;s1&#41; && sizeof (&#40;s1&#41;&#91;0&#93;) == 1       \
                     && sizeof (&#40;s2&#41;&#91;0&#93;) == 1 && strlen &#40;s1&#41; < 4              \
                     ? (__builtin_constant_p &#40;s2&#41; && sizeof (&#40;s2&#41;&#91;0&#93;) == 1    \
                        ? __strcmp_cc (&#40;const unsigned char *) &#40;s1&#41;,          \
                                       &#40;const unsigned char *) &#40;s2&#41;,          \
                                       strlen &#40;s1&#41;)                           \
                        &#58; __strcmp_cg (&#40;const unsigned char *) &#40;s1&#41;,          \
                                       &#40;const unsigned char *) &#40;s2&#41;,          \
                                       strlen &#40;s1&#41;))                          \
                     &#58; (__builtin_constant_p &#40;s2&#41; && sizeof (&#40;s1&#41;&#91;0&#93;) == 1    \
                        && sizeof (&#40;s2&#41;&#91;0&#93;) == 1 && strlen &#40;s2&#41; < 4           \
                        ? (__builtin_constant_p &#40;s1&#41;                          \
                           ? __strcmp_cc (&#40;const unsigned char *) &#40;s1&#41;,       \
                                          &#40;const unsigned char *) &#40;s2&#41;,       \
                                          strlen &#40;s2&#41;)                        \
                           &#58; __strcmp_gc (&#40;const unsigned char *) &#40;s1&#41;,       \
                                          &#40;const unsigned char *) &#40;s2&#41;,       \
                                          strlen &#40;s2&#41;))                       \
                        &#58; __strcmp_gg (&#40;s1&#41;, &#40;s2&#41;)))))
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Help request for debugging ICS

Post by hgm »

Ah, that explains why that single & (i.e. one argument of the wrong type) would give me such a shitload of warnings, many repeated multiple times. It is a macro, and its expansion introduces severalstrlen calls on each of the strcmp arguments, also on the wrong one.

What confused me here is that there already was a strlen call in the source code, and that the warning doesn't say what the argument of the call was it complains about.

Thanks for clearing it up. This makes it certain that the warnings were inocent, as the pointers were indeedpointing to an array of characters at the right address. Nevertheless it is nice I now silenced them.