From: tr.17687@z991.linuxsc.com   
      
   scott@slp53.sl.home (Scott Lurndal) writes:   
      
   > highcrew writes:   
   >   
   >> On 1/6/26 3:50 PM, Waldek Hebisch wrote:   
   >>   
   >>> Well, '(void)*foo' effectively says "foo" is not a null pointer   
   >>> (otherwise if would be undefined behaviour). Good optimizer   
   >>> will_not_ dereference foo, but keep information for further   
   >>> use.   
   >>   
   >> Hehe, now that I understand more of UB, that is correct, but   
   >> I don't think you can *rely* on the optimizer behavior, can you?   
   >   
   > Say you have a function xxx defined in a header file, but that   
   > function is only used in certain source files that include that   
   > header file.   
   >   
   > int   
   > xxx(const char *a, size_t b)   
   > {   
   > /* do something with a and b */   
   > }   
   >   
   > When compiling with -Wall, a translation unit that doesn't   
   > reference 'xxx' yet requires other components of the   
   > header file will get a warning (error with -Werror) that   
   > the function was unreferenced. It is not uncommon to   
   > make a void reference to the function in those translation   
   > units to avoid the warning, e.g.   
   >   
   > yyy.c:   
   >   
   > #include "xxx.h"   
   >   
   > int   
   > yyy(...)   
   > {   
   >    
   > (void)xxx;   
   > }   
      
   It seems better to address this problem in the header file   
   itself. It's easy to do that by adding a second function   
   in the header file and having them mutually reference   
   each other.   
      
   > xxx in this context devolves to a function pointer, IIUC.   
      
   Just use (void)&xxx. Now you're sure.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|