Age of Reason

Random musing of books and stuff I am reading.

2005/01/10

Enquire within for LP64

The program enquire.c will tell you a lot about your machine.
Here is how to compile it on HP/UX
> cc +DA2.0W +w1 +M2 enquire.c     


Use the flags +w1 for warnings, +M2 for 64bits

These are the kind of problems you should look out for:


/714: Function "malloc" called with no prototype or definition inscope
/724: Initialization converts default int return type to pointer
/722:.*cast converts 32 bit constant to pointer
/725:.*cast converts 32 bit integer to pointer
/727:.*cast truncates pointer into 32 bit integer
/729:.*converts int* to long*
/732:.*different types treated as unsigned
/740:.*casting to a smaller size may truncate
/530:.*casting from loose to strict alignment
/720:.*Assignment may overflow
A simple example that has many of the problems
> pr -n x.c

1 void main(){
2 int *x, *q, i;
3 long l=-1;
4 x = malloc(sizeof(int)*10);
5 (int*)i;
6 (int) &i;
7 (long*)&i;
8 i = l;
9 }

hp64> cc +DA2.0W +M2 +w1 -Aa x.c

line 4: warning 714: Function "malloc" called with no prototype or definition in scope.
line 4: warning 724: LP64 migration: Assignment converts default int return type to pointer "x".
line 5: warning 725: LP64 migration: Cast converts 32 bit integer to pointer.
line 6: warning 727: LP64 migration: Cast truncates pointer into 32 bit integer.
line 7: warning 530: LP64 migration: Casting from loose to strict alignment: Resulting pointer may be misaligned.
line 7: warning 729: LP64 migration: Cast converts int* to long*.
line 8: warning 720: LP64 migration: Assignment may overflow integer "i".


Sorting LP64 warnings by problem types for ease in fixing

> make 2>&1 | grep LP64 | xsort 'warning:\s+\S+:' | align warn > lp64.log
> vim -q lp64.log
> emacs lp64.log
> M-x compilation-minor-mode
> M-x next-error
; if emacs can't find files, set
; (setq compilation-search-path '("dir1" "dir2")) C-x C-e
To be continued.

0 Comments:

Post a Comment

<< Home