Find the answer to your Linux question:
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.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    5

    Question Commenting C++ style in C cause problems?


    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 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?

  2. #2
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    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.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,558
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •