Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » C compiler does not recognize // in line comments(expected expression before '/' token)
C compiler does not recognize // in line comments [message #1731573] Sat, 07 May 2016 00:02 Go to next message
Cris Harrison is currently offline Cris HarrisonFriend
Messages: 13
Registered: July 2012
Location: Fort Worth, Texas
Junior Member
Ok, this is the problem: I use yoxos to keep my eclipse up to date: and the other day I was upgraded to Mars .2 my C compiler (GCC tool Chain) stopped accepting '//' as comment lines, I checked other projects which had no errors, now have the same error.
Description Resource Path Location Type
expected expression before '/' token demo.c /demo1/Host line 98 C/C++ Problem


(93)       /* STOP FLYING! */
(94)  	
(95)  	printf("\n END OF THE LINE******************************** %4d \n", count );
(96)  	PLatLon( dlat, dlon );
(97)  	/* print"</body></html>"; */
(98)  	// now return
(99)  	return(1);}


I there a freaken switch somewhere that got flipped/set wrong? Confused
Thanks Cris
Re: C compiler does not recognize // in line comments [message #1731596 is a reply to message #1731573] Sat, 07 May 2016 12:21 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Quote:
my C compiler (GCC tool Chain) stopped accepting '//


Problems like these can be caused by missing quotes. Still ...
What is the build log output including the command line? You have given the summary collected by the Problems view.

Generally, '//' for comments is not standard C. GCC allows it but it may need -std=c99 to work as // wasn't allowed in C prior to that.
http://stackoverflow.com/questions/8284940/single-line-comments-in-ansi-c

More details at https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#C-Dialect-Options
and https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html#Option-Summary

FWIW, I tried using // in a test program and had no problems.


Re: C compiler does not recognize // in line comments [message #1731600 is a reply to message #1731596] Sat, 07 May 2016 15:40 Go to previous messageGo to next message
Cris Harrison is currently offline Cris HarrisonFriend
Messages: 13
Registered: July 2012
Location: Fort Worth, Texas
Junior Member
David. here is console from the last run:
05:37:32 **** Incremental Build of configuration Debug for project demo1 ****
make all
Building file: ../Host/demo.c
Invoking: GCC C Compiler
gcc -I"/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes" -O0 -g3 -Wall -c -fPIC -lm -fmessage-length=0 -ansi -fPIC -MMD -MP -MF"Host/demo.d" -MT"Host/demo.o" -o "Host/demo.o" "../Host/demo.c"
In file included from ../Host/demo.c:15:0:
/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes/demo.h:81:8: warning: extra tokens at end of #endif directive [enabled by default]
#endif INCLUDE_DEMO_H
^
In file included from ../Host/demo.c:17:0:
/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes/dme.h:20:9: warning: extra tokens at end of #endif directive [enabled by default]
#endif INCLUDE_DME_H
^
In file included from /mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes/nav_lib.h:12:0,
from ../Host/demo.c:18:
/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes/demo.h:81:8: warning: extra tokens at end of #endif directive [enabled by default]
#endif INCLUDE_DEMO_H
^
In file included from ../Host/demo.c:18:0:
/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes/nav_lib.h:101:8: warning: extra tokens at end of #endif directive [enabled by default]
#endif INCLUDE_NAV_LIB_H
^
../Host/demo.c: In function 'main':
../Host/demo.c:98:2: error: expected expression before '/' token
// now return
^
../Host/demo.c:99:2: warning: control reaches end of non-void function [-Wreturn-type]
return(1);}
^
make: *** [Host/demo.o] Error 1

05:37:32 Build Finished (took 103ms)

BTW This started when eclipse upgraded to MARS .2 for Shits & Giggles I when to another project that I was working on my radios which compiled cleanly last fall and did use // comments, and now it also puking when it sees // as well Embarrassed
I don't have a clue I have looked in the project and window configuration files till im blind. Crying or Very Sad

This source has been structured the same as I have done with eclipse and CCS6 (ti ver).

project:
->Host -> files.c
->NAV_includes -> files.h

Re: C compiler does not recognize // in line comments [message #1731605 is a reply to message #1731600] Sat, 07 May 2016 17:09 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Your problem is that the -ansi switch is being used. It is the equivalent of c90.

gcc -I"/mnt/MyData/home/harrison/NexGen/Code-Base/NAV/Server/demo1/NAV_Includes" -O0 -g3 -Wall -c -fPIC -lm -fmessage-length=0 -ansi -fPIC -MMD -MP -MF"Host/demo.d" -MT"Host/demo.o" -o "Host/demo.o" "../Host/demo.c

You need to change the dialect to at least -std=c99. Omitting the -ansi flag might work too. GCC seems to default to c99. Removing it may be difficult though so you may need to explicitly set it.

Project --> Properties --> C/C++ Build --> Settings find the Tool Settings tab and change the GCC C Compiler dialect from drop-down on right labelled Language Standard. You want c99.
Re: C compiler does not recognize // in line comments [message #1731610 is a reply to message #1731605] Sat, 07 May 2016 21:33 Go to previous messageGo to next message
Cris Harrison is currently offline Cris HarrisonFriend
Messages: 13
Registered: July 2012
Location: Fort Worth, Texas
Junior Member
thank you for get me very close.. but just changing the dialect to c99 did nothing and it still had -ansi in the build comments on the console.
So I kept on looking under:
Project --> Properties --> C/C++ Build --> Settings find the Tool Settings tab -> Miscellaneous
I unchecked Support ANSI programs!! -
now it works!! Very Happy
Re: C compiler does not recognize // in line comments [message #1731611 is a reply to message #1731610] Sat, 07 May 2016 23:22 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Nice to know there's a misplaced dialect option. I don't use Eclipse to generate my makefiles and it never occurred to me to look elsewhere for one.

You could have solved this long ago by merely googling for "Single line comments in Ansi-C" or similar. I also came across your SO post. The folks there didn't think much of your question (a bit unfairly perhaps) however one did comment on the need for c99. Should have sparked your curiosity.
Re: C compiler does not recognize // in line comments [message #1731656 is a reply to message #1731611] Mon, 09 May 2016 05:27 Go to previous messageGo to next message
Cris Harrison is currently offline Cris HarrisonFriend
Messages: 13
Registered: July 2012
Location: Fort Worth, Texas
Junior Member
I know I got crushed over at SO I think they are f'n full of themselves! I kept on looking in the wrong location, and then read the article about the difs between ANSI and C99. It is very misleading. Its like im in a freekn time warp. or should I say like the movie "Groundhog Day"!! over and over and over. I was looking in the wrong direction, like a chicken without its head.
Do yourself a favor if you must write in Perl (good for HTML), please don't try and convert it to C, it does not go well. That's what this project is about. I know my small demo 8865 chars in Perl is now 1252 chars of .c and 4579 chars of .h to be honest, I added a new section on calculating "Slant Range" distances. for the simulator. I figure it should have been around 12k long. and is taking way to long to code.. As I have to add in ethernet packet system.
thanks Again.
Cris.
BTW I blog up at www.element14.com/community/people/phoenixcomm/blog
Re: C compiler does not recognize // in line comments [message #1731696 is a reply to message #1731656] Mon, 09 May 2016 10:59 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Not to necessarily defend what happened but I can see why the question was down-voted.

On the surface it seems a reasonable question but:
1) it was mistagged. You tagged it c, gcc, gcc-warning but your question clearly revolved around a recent update of Ecliipse. Had nothing to do with gcc really.
2) similar questions (about C specifically) had been asked a lot. You could have found them with little effort.

There should have been a little more leniency for a low rep questioner and someone could have stepped in and reworded it for you. Somewhat disconcertingly, they pass out badges for down-voting a question. I think down-voters should be required to explain their down-votes. But then, I'm not in charge.

Even here, you have been a bit sloppy with at least one of your posts. You titled it eclipse C project with the subtitle/summary (unknown error messages) and didn't really ask a question. The content was mostly the log output. So, lacking a question and keying off the summary, I explained several of the messages. Your response was surprisingly: I knew that. Surprising because the subtitle was "unknown error messages".

BTW: nice wording of your answer at SO. Couldn't have worded it better myself. You're welcome. Don't make a habit of doing that.

---

I usually prototype in Perl and R depending on the task. With object oriented Perl the jump to C++ is fairly straightforward and uncomplicated. I only write in C if I have to and consider it one step above having to write in assembly language. In the first few spacecraft projects I worked on, the onboard software was entirely in assembly language (with scaled integer arithmetic!). Nowadays, C is used a lot but still almost as tedious as assembly. On some projects it's a requirement imposed from above.

[Updated on: Mon, 09 May 2016 11:17]

Report message to a moderator

Re: C compiler does not recognize // in line comments [message #1731759 is a reply to message #1731696] Tue, 10 May 2016 00:08 Go to previous message
Cris Harrison is currently offline Cris HarrisonFriend
Messages: 13
Registered: July 2012
Location: Fort Worth, Texas
Junior Member
you are really correct but my project the day before the upgrade worked!? So I did not think of the ANSI <-> C99 crud. So what can I say the comment of the upgrade WAS a red herring. LOL LTR
Previous Topic:added new library but still eclipse cannot find it
Next Topic:No thread names in debugger
Goto Forum:
  


Current Time: Tue Mar 19 08:16:02 GMT 2024

Powered by FUDForum. Page generated in 0.02436 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top