libshell: operation on '_Fcin.fcptr' may be undefined
Building with gcc 6:
../common/sh/lex.c: In function 'sh_lex': ../common/include/fcin.h:49:39: error: operation on '_Fcin.fcptr' may be undefined [-Werror=sequence-point] #define fcseek(n) ((char*)(_Fcin.fcptr+=(n))) ^ ../common/sh/lex.c:1089:7: note: in expansion of macro 'fcseek' fcseek(state-(fcseek(0))); ^~~~~~ cc1: all warnings being treated as errors
Updated by Toomas Soome about 4 years ago
The background for this warning is about the fact that not all operations have clearly defined sequence order, and so the compiler is trying to warn about such cases, so that we would know that this particular sequence may end up producing different results.
The solution used in this particular case is to split the pointer operation to separate units by using temporary variable for middle result. Note the problem is there because the fcseek() is macro and is expanded by preprocessor, so we can not assume the function like semantics.
Of course the alternate solution would be to convert fcseek() to real function, thus achieving the determined sequence points.
Updated by Electric Monk almost 4 years ago
- Status changed from In Progress to Closed
- % Done changed from 90 to 100
commit f25e629a56ba86e6dfc1e50a16f54fdffee36eac Author: Toomas Soome <email@example.com> Date: 2017-08-01T19:03:15.000Z 8224 libshell: operation on '_Fcin.fcptr' may be undefined Reviewed by: Marcel Telka <firstname.lastname@example.org> Reviewed by: Robert Mustacchi <email@example.com> Approved by: Richard Lowe <firstname.lastname@example.org>