HP C/aC++ Version 6 Features to Improve Developer Productivity

4
+wendian
This option enables diagnostics that identify areas in the source code that might have porting issues
between little-endian and big-endian. For example
de-reference which could cause endian-dependent behavior
Union definition that is endian dependent
Example
$ cat endian.c
union u1 {
char c[4];
int v;
};
$ cc -c +wendian endian.c
"endian.c", line 1: warning #4289-D: endian porting: the
definition of the union may be endian dependent
union u1 {
^
+wlock
This option detects multi-threaded programming issues and enables diagnostics for potential errors
in using lock/unlock calls in multi-threaded programs that use the pthread library. This is based on
cross-module analysis performed by the compiler, which is much more powerful compared to simple
scanning and parsing tools. The +wlock option implicitly enables a limited form of cross-module
analysis even if -ipo or +O4 options are not specified. This may lead to a significant increase in the
compile time in comparison to a build without the +wlock option. Using this option may result in the
compiler invoking optimizations other than those which are part of the specified optimization level. If
+wlock is used with -ipo or +O4 option, the generated code is not affected and the compile time
does not increase much.
The problems detected by +wlock diagnostics include
acquiring an already acquired lock
releasing an already released lock
unconditionally releasing a conditionally acquired lock
Example
$ cat lock.c
#include <pthread.h>
#include <stdio.h>
int a;
pthread_mutex_t Mutex;
void perform_operation(pthread_mutex_t* mutex1, int
increment, int* global) {
if (increment > 10){
int status = pthread_mutex_lock(mutex1);
}
*global = *global + increment;
int status = pthread_mutex_unlock(&Mutex);
}
int main(void) {
int i;
scanf("%d", &i);
perform_operation(&Mutex, i, &a);
printf("%d is value\n", a);
}
$ cc +wlock lock.c