patch for Stratus (and Solaris) cast error

David Collier-Brown David.Collier-Brown at canada.sun.com
Mon Jul 17 14:38:09 GMT 2000


  Back in May, Ron Alexander found an "extra" cast in SMB_ASSERT,
which messed up his Stratus ANSI compilers and pulled warnings
from the Sun CC5.0 compilers.

  Fixing it is trivial: remove (void) from before the 0 in the
define, thusly
--------
diff -c smb.h smb.h.fixed
*** smb.h       Mon Jul 17 10:30:42 2000
--- smb.h.fixed Mon Jul 17 10:30:36 2000
***************
*** 1843,1849 ****
     pointer */
  #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
  
! #define SMB_ASSERT(b) ((b)?(void)0: \
          (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
                 __FILE__, __LINE__)), smb_panic("assert failed")))
  #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0]))
>= (n))
--- 1843,1849 ----
     pointer */
  #define ZERO_ARRAY(x) memset((char *)(x), 0, sizeof(x))
  
! #define SMB_ASSERT(b) ((b)? 0: \
          (DEBUG(0,("PANIC: assert failed at %s(%d)\n", \
                 __FILE__, __LINE__)), smb_panic("assert failed")))
  #define SMB_ASSERT_ARRAY(a,n) SMB_ASSERT((sizeof(a)/sizeof((a)[0]))
>= (n))
------

According to my understanding of ANSI C, the number 0 is distinguished
by being a valid value of all pointer and integral types, and so 
should be accepted by any ANSI compiler.

My understanding of (void) 0 is that it is meaningless: it's not
a legal initializer for a type.  I suspect it was introduced to
get past a buggy compiler!

If this is fixed, the Stratus port is done (and a small Slolaris bug
is fixed).  Could one of the developers review this, and apply the
above if they're convinced?

--dave (back from Newfoundland) c-b

[for reference:
> > 067** 1081: A void object is referenced in a context where a valid
> >       object is required; an object of type int is assumed.]
-- 
David Collier-Brown,  | Always do right. This will gratify some people
185 Ellerslie Ave.,   | and astonish the rest.        -- Mark Twain
Willowdale, Ontario   | //www.oreilly.com/catalog/samba/author.html
Work: (905) 415-2849 Home: (416) 223-8968 Email: davecb at canada.sun.com


More information about the samba-technical mailing list