HP C/aC++ for PA-RISC Software manual +w64bit, +wdriver, +wendian

Models: C/aC++ for PA-RISC Software

1 230
Download 230 pages 50.97 Kb
Page 71
Image 71

+w64bit

The +w64bit option enables warnings that help detection of potential problems in converting 32-bit applications to 64-bit. The option is equivalent to the +M2 option.

+wdriver

The +wdriver option enables warnings for PA-RISC options that would otherwise be ignored silently on Integrity servers. With the addition of this option in version A.06.05, a number of warnings for PA options that had been reported by previous compiler versions were changed to be silently ignored by default. The intent is to give good PA-RISC to Integrity makefile compatibility by default, but provide this option to help users clean up unnecessary or misleading use of legacy options when desired.

+wendian

This option allows the user to identify areas in their source code that might have porting issues when going between little-endianand big-endian.

+wendian will warn of a de-reference that could cause endian-dependent behavior:

char charVal = *(char *) int_ptr;

short shortVal = ((short *) long_ptr)[0];

This warning can be suppressed by adding an extra cast:

char charVal = *(char *) (void *)int_ptr; // OK

+wendian warns that the initialization which may be endian-dependent, such as using hex constants to init byte arrays:

char a[4] = { 0x11, 0x22, 0x33, 0x44 }; char b[4] = { 'a', 'b', 'c', 'd'}; // OK

This warning can be suppressed by not using a hex/octal constant:

char a[4] = { 17, 0x22, 0x33, 0x44 }; // OK

+wendian also warns of unions that make assumptions about data layout:

union u1 { char c[4]; int v; };

union u2 { long long ll; short s[4]; char c[8]; };

This warning can be suppressed by adding a dummy member:

union u1 { // OK char c[4];

int v;

char dummy; };

Another type of warning is on the use of IO functions that read/write persistent data from files that may be endian-dependent:

read(0, &i, sizeof(i));

fread(&ai[0], sizeof(int), elems_of(ai, int), stdin);

write(1, &i, sizeof(i));

fwrite(&ai[0], sizeof(int), elems_of(ai, int), stdout);

This warning can be suppressed by adding an extra cast:

fread((char*)(void*)ai, sizeof(char), 1, stdin); // OK

Another +wendian warning captures cases where a cast when later dereferenced can cause endian issues.

Porting Options 71

Page 71
Image 71
HP C/aC++ for PA-RISC Software manual +w64bit, +wdriver, +wendian, This warning can be suppressed by adding an extra cast