Subject: misc/3614: bitstr_t macros expand to compound statements
To: None <gnats-bugs@gnats.netbsd.org>
From: None <jarle@runit.sintef.no>
List: netbsd-bugs
Date: 05/13/1997 21:21:34
>Number:         3614
>Category:       misc
>Synopsis:       bitstr_t macros expand to compound statements
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 13 12:35:01 1997
>Last-Modified:
>Originator:     Jarle Greipsland
>Organization:
SINTEF/RUNIT
	
>Release:        1.2
>Environment:
	
System: NetBSD darling.runit.sintef.no 1.2.1 NetBSD 1.2.1 (DARLING) #0: Sat Apr 12 17:18:57 MET DST 1997 jarle@darling.runit.sintef.no:/usr/src/sys/arch/i386/compile/DARLING i386


>Description:
Some of the macros that operate on bitstr_t will expand into compound
statments when run through cpp.  This is certainly unexpected (and
unwanted) behavior for statements like:
if (something)
	bit_nclear(bitstr, 0, max);
else
	bit_nset(bitstr, 0, max);
The C compiler will now balk on the superfluous ';' in:
if (something)
	{ ... };
else
	{ ... };

	
>How-To-Repeat:
Write a program that uses the bitstr_t manipulating macros heavily.
	
>Fix:
	
Apply the attached diff, which turns the compound statements into
non-compound ones.

*** /usr/include/bitstring.h.orig	Tue May 13 20:56:27 1997
--- /usr/include/bitstring.h	Tue May 13 20:58:08 1997
***************
*** 70,74 ****
  
  				/* clear bits start ... stop in bitstring */
! #define	bit_nclear(name, start, stop) { \
  	register bitstr_t *_name = name; \
  	register int _start = start, _stop = stop; \
--- 70,74 ----
  
  				/* clear bits start ... stop in bitstring */
! #define	bit_nclear(name, start, stop) do { \
  	register bitstr_t *_name = name; \
  	register int _start = start, _stop = stop; \
***************
*** 77,84 ****
  		_start++; \
  		} \
! }
  
  				/* set bits start ... stop in bitstring */
! #define	bit_nset(name, start, stop) { \
  	register bitstr_t *_name = name; \
  	register int _start = start, _stop = stop; \
--- 77,84 ----
  		_start++; \
  		} \
! } while (0)
  
  				/* set bits start ... stop in bitstring */
! #define	bit_nset(name, start, stop) do { \
  	register bitstr_t *_name = name; \
  	register int _start = start, _stop = stop; \
***************
*** 87,94 ****
  		_start++; \
  		} \
! }
  
  				/* find first bit clear in name */
! #define	bit_ffc(name, nbits, value) { \
  	register bitstr_t *_name = name; \
  	register int _bit, _nbits = nbits, _value = -1; \
--- 87,94 ----
  		_start++; \
  		} \
! } while (0)
  
  				/* find first bit clear in name */
! #define	bit_ffc(name, nbits, value) do { \
  	register bitstr_t *_name = name; \
  	register int _bit, _nbits = nbits, _value = -1; \
***************
*** 99,106 ****
  		} \
  	*(value) = _value; \
! }
  
  				/* find first bit set in name */
! #define	bit_ffs(name, nbits, value) { \
  	register bitstr_t *_name = name; \
  	register int _bit, _nbits = nbits, _value = -1; \
--- 99,106 ----
  		} \
  	*(value) = _value; \
! } while (0)
  
  				/* find first bit set in name */
! #define	bit_ffs(name, nbits, value) do { \
  	register bitstr_t *_name = name; \
  	register int _bit, _nbits = nbits, _value = -1; \
***************
*** 111,115 ****
  		} \
  	*(value) = _value; \
! }
  
  #endif /* !_BITSTRING_H_ */
--- 111,115 ----
  		} \
  	*(value) = _value; \
! } while (0)
  
  #endif /* !_BITSTRING_H_ */
>Audit-Trail:
>Unformatted: