GCC warning when assigning pointers
Closed this issue · 2 comments
Josef Templ wrote:
Dear Oleg,
I guess you are using a version of gcc which has an option turned on for warning about incompatible pointers.
I see two possible solutions,
- Turn off that option
- Emit explicit type casts for such assignments.
For the latter see ofront module OfrontOPV.stat in line 925. An explicit type cast is already emitted there but only for named pointer types i.e. where l^.typ^.strobj # NIL. Your example uses an anonymous pointer type that falls through. So I guess you have to refine that pattern and add the case where l^.typ^.BaseTyp # NIL & l^.typ^.BaseTyp^.strobj # NIL by casting with (BaseTypName*).
Josef
Dear Josef,
Thank you very much for the answer.
My first attempt to fix it according to what you said resulted in this code (see attached picture, my additions are in green).
However, this causes explicit type casting to appear when both pointers are of the same type. For example, this occurs in the Files module:
Left side:
f->next = Files_files; Files_files = f;
Right side:
f->next = (Files_FileDesc*)Files_files; <- the same pointer types Files_files = (Files_FileDesc*)f; <- the same pointer types
So I made the check a bit more complicated and added another condition
" & (l^.typ^.BaseTyp # r^.typ^.BaseTyp) "
This code works correctly at first glance.