5 ms·
Maybe this is why my C tutor used to say over and over again "never use C++ style comments even though Visual studio let's you do it".
by dools 15y ago
Maybe this is why my C tutor used to say over and over again "never use C++ style comments even though Visual studio let's you do it".
- jmj42 15y agoMy thoughts, exactly. Perhaps I'm a little overly pedantic, but it annoys me to extremes when I find c++ style comments littering up c
- burgerbrain 15y agoWhat I do is I turn on my compilers warnings for C++ comments in C code, then use C++ comments with all my TODO comments. That way I know if there are any outstanding TODOs when I go to build.
- mahmud 15y agoIt's not a warning in GCC. The -ansi flag, and older standards, err on C++ comments, but they're still valid input for C99 mode(s).
- burgerbrain 15y agoWith -pedantic you can get: warning: C++ style comments are not allowed in ISO C90 [enabled by default] Might be worth noting at this point since I'll already halfway though the GCC manpage again, that -Wcomments seems to be exactly for the sort of situation the author of the article found himself in.
- acqq 15y agoIt depends on what you write. If your goal isn't portability, using // has nothing to do with author's unawareness of the semantics of the line continuation character in C (that is, escaped line end character). It's a C feature since forever, and not knowing about it would bite him sooner or later even without the use of C++ comments.
- Jach 15y agoUnlikely, probably just because C++ style comments aren't valid in the C89 standard. I assume Visual Studio, like gcc, defaults to compiling with "c89+", their own flavor of the c89 standards with sane extensions like C++ comments and not needing to declare variables before all statements. My C class forced us to always compile gcc with "-Wall -Wextra -pedantic -ansi", and I forget the "cl" and Borland arguments. (Fortunately Makefiles were usually provided.) I mean, if this is a reason not to use C++ style comments, then it seems like a very weak one of many reasons not to use C++, I don't think that was intended.
- dools 15y agoOh right, that would be it: this was a mechatronic engineering course and when we first learned C they taught it in Visual Studio. It sounds like your C class was better :) I wish they'd taught us initially to do the compiling/linking etc. ourselves. I guess they wanted to just teach coding and leave the rest as an exercise for us to learn independently (the irony of course being that learning all that other stuff seems to me to be vastly more complex and involved, and in need of formal educational structure, than writing code, but anyway ... ) So I guess most of the C compilers for the target microcontrollers we were working with in later courses would have used the C89 standard
- to3m 15y agoIt's marginally more likely that your C tutor hadn't noticed that //-style comments are now C-style too, and imagined that Visual Studio permits it as some kind of non-standard extension. (Correctly arguing he is right, then reasonably rebutting this argument, is an exercise for the reader.) This feature has only been with us as part of the standard since 1999, which in geological terms is merely the blink of an eye. I imagine this is why so many people seem not to know about it.