Re: how to make a macro work as a single line if stmt without braces

Liste des GroupesRevenir à cl c  
Sujet : Re: how to make a macro work as a single line if stmt without braces
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 23. Sep 2024, 10:14:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vcrbgv$2l5s8$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 23/09/2024 09:06, Richard Harnden wrote:
On 23/09/2024 07:16, David Brown wrote:
On 22/09/2024 22:39, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 22/09/2024 16:11, Kaz Kylheku wrote:
[...]
Also GCC has been able to diagnose misleading indentation for some
years now.
>
How many years was that out of the last 52? How exactly do you turn it
on? Since -Wall -Wpedantic -Wextra doesn't report it.
>
The -Wmisleading-indentation option was added to gcc on 2015-05-12,
and incorporated into -Wall 2015-12-10.  gcc 6.1.0 has the option
and includes it in -Wall; gcc 5.3.0 does not.  (Are you using a gcc
release that old?)  It uses the -ftabstop= option (defaulting to 8)
to determine whether indentation lines up or not.
>
Inconsistent tabstops and mixing of spaces and tabs can certainly
cause problems.
>
>
That would be detected quite easily if the default for -ftabstop were, say, 27.  Then the chance of accidentally matching indents with tabs and spaces would be negligible.
>
 Isn't that the opposite of what you want, though?
 
What I would be looking for in this case is a warning if I had used tabs and spaces (for indents) at different places in the code.  If the tab setting is a sensible choice - typically 4 or 8 spaces worth - then you can easily have code that looks right (in the sense of having visual indents that match the real block structure) with one setting and looks wrong with a different setting.
For example, you might write this code :
<tb>if (test)
<tb><tb>foo();
<  ><  >bar();
You've made an error here - you had intended to have both calls within the conditional.  With 4 spaces per tab when you made the error, this could be spotted by tools using tabstop settings of 4, or by a code reviewer with those settings.
However, to tools or code reviewers with tabstop settings of 8, the code would appear as:
<tb    >if (test)
<tb    ><tb    >foo();
<  ><  >bar();
Now the indentation matches the syntactical structure, and the mistake is missed.
With a tabstop of 27, the "if" and "bar()" lines do not match up, and the mistake can be flagged.
Of course a tabstop of 27 is not necessary - anything other than a sane value of 4 or 8 would catch almost anything.  But having a bit of extra distance also catches cases of tab then space typos.
And there could also be a warning that checked directly for mixes of tabs and spaces in indents.  But such mixes can happen when moving or copying code between files, and there are some people who like to mix 8-space tabs with 4 explicit spaces in their code.

Date Sujet#  Auteur
21 Sep 24 * how to make a macro work as a single line if stmt without braces61Mark Summerfield
21 Sep 24 +- Re: how to make a macro work as a single line if stmt without braces1Lawrence D'Oliveiro
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces50David Brown
21 Sep 24 i`* Re: how to make a macro work as a single line if stmt without braces49Andrey Tarasevich
21 Sep 24 i +- Re: how to make a macro work as a single line if stmt without braces1Bart
21 Sep 24 i +- Re: how to make a macro work as a single line if stmt without braces1Opus
21 Sep 24 i +* Re: how to make a macro work as a single line if stmt without braces5Keith Thompson
22 Sep 24 i i`* Re: how to make a macro work as a single line if stmt without braces4Andrey Tarasevich
22 Sep 24 i i +- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
22 Sep 24 i i +- Re: how to make a macro work as a single line if stmt without braces1David Brown
27 Sep 24 i i `- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
22 Sep 24 i +* Re: how to make a macro work as a single line if stmt without braces25David Brown
22 Sep 24 i i`* Re: how to make a macro work as a single line if stmt without braces24Kaz Kylheku
22 Sep 24 i i +* Re: how to make a macro work as a single line if stmt without braces21Bart
22 Sep 24 i i i+* Re: how to make a macro work as a single line if stmt without braces14Michael S
22 Sep 24 i i ii+- Re: how to make a macro work as a single line if stmt without braces1Bart
24 Sep 24 i i ii`* Re: how to make a macro work as a single line if stmt without braces12Tim Rentsch
24 Sep 24 i i ii +* Re: how to make a macro work as a single line if stmt without braces5Andrey Tarasevich
24 Sep 24 i i ii i+- Re: how to make a macro work as a single line if stmt without braces1David Brown
24 Sep 24 i i ii i+* Re: how to make a macro work as a single line if stmt without braces2Bart
24 Sep 24 i i ii ii`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
27 Sep 24 i i ii i`- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
24 Sep 24 i i ii `* Re: how to make a macro work as a single line if stmt without braces6Bart
24 Sep 24 i i ii  +* Re: how to make a macro work as a single line if stmt without braces2Keith Thompson
24 Sep 24 i i ii  i`- Re: how to make a macro work as a single line if stmt without braces1Bart
24 Sep 24 i i ii  `* Re: how to make a macro work as a single line if stmt without braces3Kaz Kylheku
24 Sep 24 i i ii   `* Re: how to make a macro work as a single line if stmt without braces2Bart
25 Sep 24 i i ii    `- Re: how to make a macro work as a single line if stmt without braces1Kaz Kylheku
22 Sep 24 i i i`* Re: how to make a macro work as a single line if stmt without braces6Keith Thompson
23 Sep 24 i i i `* Re: how to make a macro work as a single line if stmt without braces5David Brown
23 Sep 24 i i i  `* Re: how to make a macro work as a single line if stmt without braces4Richard Harnden
23 Sep 24 i i i   `* Re: how to make a macro work as a single line if stmt without braces3David Brown
23 Sep 24 i i i    `* Re: how to make a macro work as a single line if stmt without braces2Richard Harnden
23 Sep 24 i i i     `- Re: how to make a macro work as a single line if stmt without braces1David Brown
22 Sep 24 i i +- Modern text editor - 'bout time someone paid attention to keeping the thread title relevant!!! (Was: how to make a macro work as a single line if stmt without braces)1Kenny McCormack
22 Sep 24 i i `- Re: how to make a macro work as a single line if stmt without braces1David Brown
28 Sep 24 i `* Re: how to make a macro work as a single line if stmt without braces16Tim Rentsch
28 Sep 24 i  +* Re: how to make a macro work as a single line if stmt without braces5Michael S
29 Sep 24 i  i`* Re: how to make a macro work as a single line if stmt without braces4Tim Rentsch
29 Sep 24 i  i `* Re: how to make a macro work as a single line if stmt without braces3Michael S
30 Sep 24 i  i  +- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
30 Sep 24 i  i  `- Re: how to make a macro work as a single line if stmt without braces1Alan Mackenzie
29 Sep 24 i  `* Re: how to make a macro work as a single line if stmt without braces10Andrey Tarasevich
29 Sep 24 i   `* Re: how to make a macro work as a single line if stmt without braces9Tim Rentsch
29 Sep 24 i    `* Re: how to make a macro work as a single line if stmt without braces8Andrey Tarasevich
29 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Michael S
30 Sep 24 i     +* Re: how to make a macro work as a single line if stmt without braces3Keith Thompson
30 Sep 24 i     i`* Re: how to make a macro work as a single line if stmt without braces2Kaz Kylheku
30 Sep 24 i     i `- Re: how to make a macro work as a single line if stmt without braces1Janis Papanagnou
30 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
30 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Kaz Kylheku
30 Sep 24 i     `- Re: how to make a macro work as a single line if stmt without braces1David Brown
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Bart
21 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Mark Summerfield
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Ike Naar
21 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Tim Rentsch
22 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
21 Sep 24 +- Re: how to make a macro work as a single line if stmt without braces1Andrey Tarasevich
21 Sep 24 `* Re: how to make a macro work as a single line if stmt without braces2Blue-Maned_Hawk
24 Sep 24  `- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal