Re: My idea of fully-portable C code



In message <bf1f13dd-5bb1-4da7-b339-dbfc46944cca@xxxxxxxxxxxxxxxxxxxxxxxxxxx>, Tomás Ó hÉilidhe <toe@xxxxxxxxxxx> writes
On May 13, 7:59 pm, Hans-Bernhard Bröker <HBBroe...@xxxxxxxxxxx>
wrote:
> #define TOTAL_BITS_NEEDED (QUANTITY_CHUNKS * BITS_PER_CHUNK)

Bad macro.  Parentheses missing around QUANTITY_CHUNKS and
BITS_PER_CHUNK leave the code vulnerable to funny definitions of those
constants (e.g. #define BITS_PER_CHUNK 2+3)  The same problem occurs
repeatedly later on.


You're confusing things. A macro is a self-contained, self-sufficient
entity. If I have a macro called QUANTITY_CHUNKS, then it should be
able to be used on its own without parentheses. If it needs
parentheses, then it is ill-formed.


Now you are running counter to most standards and guides for portability and safety.


--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



.



Relevant Pages

  • Re: C99: Suggestions for style(9)
    ... because it does not improve maintainability in any way. ... There is no source for confusion here, so the rule even contradicts the rule, which states not to use redundant parentheses. ... so it is clear that there is a macro at work. ... the parentheses are not redundant) would be for local debugging ...
    (freebsd-hackers)
  • Re: rvalue
    ... >The outer parentheses surrounding the entire macro definition are ... >necessary (and the original version of the macro had them). ... >referring to parentheses around each parameter reference within the ... >certain about the parentheses surrounding mw; ...
    (comp.lang.c)
  • Re: My idea of fully-portable C code
    ... BITS_PER_CHUNK leave the code vulnerable to funny definitions of those ... If I have a macro called QUANTITY_CHUNKS, ... able to be used on its own without parentheses. ... #define FOO BAR+3 ...
    (comp.arch.embedded)
  • Re: parentheses find function
    ... In article, Tim ... would like to make some macro that would go through a document and ... Wildcard search and replace will do what you want. ... should find all strings enclosed in parentheses and their parentheses. ...
    (microsoft.public.mac.office.word)
  • Re: Difference
    ... in the comma-separated list bounded by the parentheses in a function- ... like macro invocation ... the macro name in a function-like macro definition ...
    (comp.lang.c)