From: downing.nick@gmail.com (Nick Downing)
Subject: [TUHS] // comment in C++
Date: Fri, 10 Feb 2017 00:31:18 +1100 [thread overview]
Message-ID: <CAH1jEzZGafPhu6qJ4z6v2koda6EDCKf0jZ65YcQ1_sLoS+-93Q@mail.gmail.com> (raw)
In-Reply-To: <306BEA6F-6E6C-4470-AC6C-DF6D848CBBFF@me.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3527 bytes --]
Haha well I never liked that idiom but I recently found out that
#ifdef was present in the first CPPs whereas #if was much later. So
that's why #ifdef notdef is seen a lot in old code. Anyway, personally
I use #if 0 and #if 1 quite a lot for debugging or questionable stuff.
For a while, I was quite into the idea of doing compile time options
like #define SOME_OPTION 1 and then using #if SOME_OPTION, as I felt
it was nicer than #ifdef SOME_OPTION. But I've changed my mind, as
this is pretty nonstandard usage and can be misleading. It's also not
really safer than #ifdef, since for some reason CPP accepts undefined
symbols and treats them as 0 in a #if statement. Go figure.
cheers, Nick
On Thu, Feb 9, 2017 at 11:18 PM, Brantley Coile <brantleycoile at me.com> wrote:
> That’s a good convention. I use the convention that the permanent comments use the slash-splat form and the slash-slash from is used for temporary comment that will need attention later. They are TODO comments.
>
> I also use empty comments in the first column to note debugging stuff to remove laters. For example:
>
> void
> main(int argc, char **argv)
> {
> ARGBEGIN {
> default:
> usage();
> } ARGEND
> /**/ print(“argc=%d argv=%p\n”, argc, argv);
> /**/ if (argc == 3)
> /**/ print(“that funny number again\n”);
> if (argc == 0) {
> usestdin();
> …
> }
>
> This lets the flow of the test logic clear yet is easy to find and remove the code later.
>
> I also use “#ifdef notdef” to comment out blocks of code. Have done since v7 days. Once I worked with a guy who saw the ifdefs and wondered what the function was that was def’ed out. He added -Dnotdef and all hell broke out!
>
> Brantley
>
>> On Feb 8, 2017, at 11:55 PM, Steve Johnson <scj at yaccman.com> wrote:
>>
>> Well, personally I use // for almost all comments in C/C++. I reserve /* */ for commenting out blocks of code. Since, for some reason, /* */ doesn't nest, if I stick to this style life is good.
>>
>> Steve
>>
>>
>>
>> ----- Original Message -----
>> From:
>> "Steve Nickolas" <usotsuki at buric.co>
>>
>> To:
>> "The Eunuchs Hysterical Society" <tuhs at tuhs.org>
>> Cc:
>>
>> Sent:
>> Wed, 8 Feb 2017 21:47:49 -0500 (EST)
>> Subject:
>> Re: [TUHS] // comment in C++
>>
>>
>> On Thu, 9 Feb 2017, Dave Horsfall wrote:
>>
>> > On Wed, 8 Feb 2017, Steve Johnson wrote:
>> >
>> >> I remember some discussion about this. In reality, a C comment really
>> >> requires you to type 8 characters, because putting anything adjacent to
>> >> the /* or */ looks terrible. Many languages used single characters
>> >> (e.g., # for make). The argument was "if you make comments easier to
>> >> type, you'll get more of them in the code" (viz. the Unix kernel). I'm
>> >> guessing Bjarne was aware of these discussions, although I don't
>> >> remember specifically that he was...
>> >
>> > My favourite C /* */ style is this:
>> >
>> > /*
>> > * foo
>> > * bar
>> > */
>>
>> This is the way I usually write my comments, too.
>>
>> > Is that what you meant? And recent C also accepts // as a comment, which
>> > I use like this:
>> >
>> > /*
>> > * This is where we do some neat stuff.
>> > */
>> > foo();
>> > weird_function(); // Yes, we need to call this here...
>> > bar();
>> >
>> > I'm quite taken by BIND, though, which accepts
>> >
>> > /* this */
>> > // this
>> > # and this.
>>
>> Unrealircd likewise accepts those 3 different types of comments.
>>
>> -uso.
>
next prev parent reply other threads:[~2017-02-09 13:31 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-08 18:06 ron minnich
2017-02-08 18:08 ` A. P. Garcia
2017-02-08 18:17 ` arnold
2017-02-08 23:39 ` Steve Johnson
2017-02-08 23:52 ` Dave Horsfall
2017-02-09 2:11 ` Corey Lindsly
2017-02-09 2:46 ` Dave Horsfall
2017-02-09 2:53 ` Corey Lindsly
2017-02-09 4:38 ` Warner Losh
2017-02-09 2:47 ` Steve Nickolas
2017-02-09 4:55 ` Steve Johnson
2017-02-09 11:59 ` Michael Kjörling
2017-02-09 21:56 ` Dave Horsfall
2017-02-10 0:17 ` Dan Cross
2017-02-10 1:58 ` Dave Horsfall
2017-02-10 2:46 ` Nemo
2017-02-10 2:49 ` Dave Horsfall
2017-02-10 9:30 ` arnold
2017-02-10 9:19 ` arnold
2017-02-09 12:18 ` Brantley Coile
2017-02-09 13:31 ` Nick Downing [this message]
2017-02-08 22:45 ` Greg 'groggy' Lehey
2017-02-08 22:50 ` Ron Natalie
2017-02-08 23:22 ` Greg 'groggy' Lehey
2017-02-09 12:12 ` Michael Kjörling
2017-02-09 12:26 ` Lars Brinkhoff
2017-02-09 14:37 ` Random832
2017-02-09 14:49 ` Random832
2017-02-09 12:31 ` Paul Ruizendaal
2017-02-09 13:07 ` Steffen Nurpmeso
2017-02-08 22:51 ` ron minnich
2017-02-08 23:22 ` Greg 'groggy' Lehey
[not found] <mailman.204.1486594285.3779.tuhs@minnie.tuhs.org>
2017-02-09 0:03 ` Paul McJones
2017-02-09 2:28 ` Marc Rochkind
2017-02-09 13:11 ` Tony Finch
2017-02-09 14:44 Noel Chiappa
2017-02-09 16:51 ` Steffen Nurpmeso
2017-02-09 19:36 ` Steffen Nurpmeso
2017-02-09 21:14 Doug McIlroy
2017-02-10 17:39 ` Steffen Nurpmeso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH1jEzZGafPhu6qJ4z6v2koda6EDCKf0jZ65YcQ1_sLoS+-93Q@mail.gmail.com \
--to=downing.nick@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).