?
Solved

gcc compiler: How do I enable C++ styled comments while leaving ANSI enabled

Posted on 2005-02-27
6
Medium Priority
?
928 Views
Last Modified: 2008-01-09
Hi experts:

I am using the following version of gcc:
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

I have a project written in pure C which is to be used in embedded system. So, I use pure C to minimize the code size.

When I compile the project, I use the -ansi flag in order to make sure the code complies with the ANSI standard. However, the down side of using this ansi flag is that I am only allowed to use C styled comments (/*comments */). This is giving me a headache when I need to use nested comments.

So, my question is: what switches/flags can I use to allow me to use C++ styled comments (// comments) while keeping the ANSI checking enabled at the same time?

Thank you all very much!
0
Comment
Question by:manchung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Assisted Solution

by:gripe
gripe earned 600 total points
ID: 13417231
Hi manchung,

gcc -c -Wp,-lang-c-c++-comments myprog.c

From here: http://www.delorie.com/djgpp/v2faq/faq8_4.html

Cheers!
0
 

Author Comment

by:manchung
ID: 13417645
Hi gripe,

Thanks very much for your quick response.

I tried adding the new flag to the CFLAGS variable in "configure.in":
  CFLAGS="$CFLAGS -ansi -Wall -Wp,-lang-c-c++-comments -Werror-implicit-function-declaration -D_GNU_SOURCE -DHAVE_GLIB -DLINUX"

However, when I ran ./configure, it erred out and the log file said:
"configure: exit 77"

Any idea?

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13417860
may be that your configure splits the CFLAGS from configure.in at -
Then I'd change CFLAGS in the Makefile after running configue (without that additional option in configure.in)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 22

Accepted Solution

by:
NovaDenizen earned 900 total points
ID: 13419359
I think you can get most of what you want if you replace your "-ansi" switch with "-std=C99".  The C99 standard is the most recent version of the ANSI standard, and one of its new features is that it permits c++ style comments.  See http://gcc.gnu.org/gcc-3.3/c99status.html for details of gcc's support for C99.
0
 

Author Comment

by:manchung
ID: 13426058
Hi NovaDenizen,

Thanks a lot for your suggestion.

With the "-ansi" switch, the compiler disallows the the use of declarations (e.g. int num;) in the middle of a block. In other words, it only allows declarations at the very beginning of a block. This is one of the features that I want.

However, with the "-std=c99" switch, the compiler does allow declarations to appear anywhere.

Is there a way to keep the strict checking? Thanks again!
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 13430705
I don't think you can pick and choose gcc features like that anymore. It used to be that when you used -ansi, that would be equivalent to picking a certain set of -f options that turned on and off certain language features.  Then you could just manually use that same set of options with a few changes that you wanted.  Now, I think, gcc doesn't have that flexibility.  You pretty much have to go all-or-nothing.  

Maybe you should find a way to automatically change your // comments into /* */ comments.  Then you could just use -ansi.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question