[Libreoffice] if (foo == sal_True)

Lubos Lunak l.lunak at suse.cz
Fri Apr 1 09:27:29 PDT 2011

On Friday 01 of April 2011, Michael Meeks wrote:
> Hi guys,
> 	I see quite a staggering number of these things around the codebase:
> $ g grep '== sal_True' | wc -l
> 744
> 	and the (less dangerous IMHO) '== sal_False' construct has ~400 (what
> positive people we are ;-)
> if( m_pDataContainer->IsModuleInstalled( E_SWRITER ) == sal_True )
> if( IsModified() == sal_True )
> if( m_bOwner == sal_True )
> etc. etc.
> 	sal_True is -1

 What makes you think so (besides possibly today's date, but then the rest of 
your mail looks ok) ?

/ure/sal/inc/sal/types.h : # define sal_True ((sal_Bool)1) 

printf("%d\n", sal_True);

> 	- which is great for unsigned bit fields and all that - 

 Not really important, but you lost me there.

> but - well, I am certain there are a whole host of creative errors
> around where a supposedly boolean value is neither 0 nor -1, and of
> course these create serious trouble were we to convert to using plain
> 'bool' more widely.

 Actually, converting to bool would have probably avoided any such possible 
trouble, as converting to bool converts any non-zero to true (which has the 
value of 1 with gcc, although I'm not quite sure the spec mandates this). So 
if in those examples above the return type and the type of the variable were 
bool, this just works (unlike sal_Bool). With bool it can break only if 
somebody does something prehistoric like 'int Buffer::isNonEmpty() const { 
return size; }'.

 Lubos Lunak
 l.lunak at suse.cz

More information about the LibreOffice mailing list