Results 1 to 3 of 3
Platform: RedHat Liinux 7.2 gcc 2.96 g++ 2.96 People here have stated that when commenting a C file, use only C commenting style (/* */) and when commenting C++ only ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-01-2011 #1
- Join Date
- Jul 2010
Commenting C++ style in C cause problems?
RedHat Liinux 7.2
People here have stated that when commenting a C file, use only C commenting style (/* */) and when commenting C++ only then use the the C++ style (//). They claim that using C++ style commenting in C code could cause issues in compiling the code.
I have not run across any problems in code I have modified and I utilize the C++ style in many instances because it is cleaner to me.
I have been using C++ style of commenting in C code for a long time. I have use it many years before I started at this job and never ran into any problems. Am I just lucky?
The real question is should I or the others here have any real concerns using C++ commenting style in C code with the platform I have indicated? If not, is are there any scenarios (e.g. versions/platforms) where we should be concerned? Do all modern C compilers support the C++ commenting style?
- 03-01-2011 #2
I am not an expert, but I thought both styles were
acceptable. If this has been your experience, you
shouldn't let superstitious people annoy you.
The place where you work may have a styling preference.
If they do not, do what seems best to you.
- 03-01-2011 #3
- Join Date
- Apr 2009
- I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
Current GNU compilers will take C++ style comments in C code, as that is part of the current C language standard. However, GCC versions prior to 3.x were of an older standard and did not generally support C++ comments. So, I generally use C comments in C code, and C++ or C comments in C++ code if I want my software to build on legacy systems.Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!