W
W Karas
Recently I wrote a macro to set a bit field at an arbitrary location in an array of some unsigned integral type. (Can't show it because it's proprietary.) The bit field is specified as a bit offset from the start of the array, and the number of bits of width. Probably a mistake, but I decided it would (somehow) be more aesthetic if the macro expanded to an expression with side effects (and useless value) rather than a (compound) statement. The expanded macro has multiple instances of this pattern:
yada-yada , (exprA ? exprB : 0), yada-yada
where exprB has side effects. GCC seems to have no complaints as long as exprB evaluates to a constant value known at compile time. But if exprB hasa variable in it, and exprA is false, GCC gives a "value not used in commaexpression" warning (using -Wall) or something like that. The -Wno-unused-value option eliminates this warning. I would like to ask 2 questions.
1) What are some problems I might miss by using -Wno-unused-value ? I thought it might disable the warning for unused variables, but that is separate and covered by -Wunused-variables.
2) Is there a more targeted way to eliminate this spurious warning? I'd hate to have to put pragmas every place I invoked the macro.
yada-yada , (exprA ? exprB : 0), yada-yada
where exprB has side effects. GCC seems to have no complaints as long as exprB evaluates to a constant value known at compile time. But if exprB hasa variable in it, and exprA is false, GCC gives a "value not used in commaexpression" warning (using -Wall) or something like that. The -Wno-unused-value option eliminates this warning. I would like to ask 2 questions.
1) What are some problems I might miss by using -Wno-unused-value ? I thought it might disable the warning for unused variables, but that is separate and covered by -Wunused-variables.
2) Is there a more targeted way to eliminate this spurious warning? I'd hate to have to put pragmas every place I invoked the macro.