In a case such as this, GCC ought to be able to prove that the signed variable is positive and therefore suppress "signed and unsigned" warnings. I see this in both C and C++.
#define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) unsigned int constrain(unsigned int index, unsigned int offset, unsigned int limit) { int adj = index - offset; adj = MAX(adj, 0); return MIN(adj, limit); /* { dg-bogus "signed and unsigned" } */ } -- Summary: suppress "signed and unsigned" warnings when signed value known to be positive Product: gcc Version: 4.3.2 Status: UNCONFIRMED Keywords: diagnostic Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zackw at panix dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37591