BUGFIX: TORTURE.C - Fixes to allow builds with Compaq C

Michael Sweet mike at easysw.com
Tue Jul 10 15:19:53 GMT 2001


"John E. Malmberg" wrote:
> ...
> > First, a C compiler should not error out from passing a pointer of
> > a different type - such strictness is reserved for C++ compilers... :)
> 
> The difference is significant, and while it may be possible to tell
> the C compiler to ignore the issue, I would think that most programmers
> would want to realize that the what they asked for is obviously not
> what they wanted.  This shows up when the pointer is passed to a routine.

That's what "warnings" are for...

> Having a volatile pointer is quite a different thing from having a
> pointer to a volatile memory location.

Yes, but until recently C had no "volatile" keyword, and do be honest
I'd rather have the compiler *not* decide if a pointer should be
volatile on its own.

> > Second, the volatile modifier is not supported by most compilers.
> > It is fairly new so I wouldn't recommend using it until more compilers
> > support it (and even then you should #define it away if the compiler
> > doesn't support it)
> 
> Using the #define in config.h may be a good idea, but the implications
> of what volatile means to a compiler indicates that it should be used
> where ever it is needed.

The volatile keyword was added to allow the compiler to make
optimizations
that assume that temporary results of pointer dereferencing won't change
when the pointer is passed to another function, or that two pointer
variables might be pointing at the same general area of memory (e.g., an
implementation of strcpy...)

> This would be in any case where the same physical memory location can be
> referenced by multiple threads or processes.  Failure to do so can result
> in the compiler missing a change to the value.

The volatile keyword isn't really meant for that; MP issues extend
well beyond C, which is why you usually use OS mechanisms for
semaphores, message queues, etc.  All volatile really buys you in
this case is a mechanism for correctly (not) caching shared global
variables.

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products                  mike at easysw.com
Printing Software for UNIX                       http://www.easysw.com




More information about the samba-technical mailing list