Date: Mon, 21 Feb 2005 18:59:51 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Kathy Quinlan <kat-free@kaqelectronics.dyndns.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Error in my C programming Message-ID: <20050221165951.GA2124@gothmog.gr> In-Reply-To: <4219C912.2070207@kaqelectronics.dyndns.org> References: <4218B960.1050403@kaqelectronics.dyndns.org> <20050220183219.GK57256@cirb503493.alcatel.com.au> <4218DEC5.1080600@kaqelectronics.dyndns.org> <20050221065844.GB81063@cirb503493.alcatel.com.au> <4219C912.2070207@kaqelectronics.dyndns.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-02-21 19:42, Kathy Quinlan <kat-free@kaqelectronics.dyndns.org> wrote:
> Peter Jeremy wrote:
>
> OK it was all to do with the comments it did not like the //comments
> ARRGGHHHH the rest of the errors were bogus as soon as I changed EVERY
> comment over to the ANSI C /*comments*/ it now works (oh and removed the
> #pragma directives from a c compiler for the AVR uC I will have to put
> all the different complier directives in different #ifdef tags :)
The quotations seem a bit messed up, so I don't know if Peter Jeremy or
Kathy Quinlan wrote the above paragraph. Whoever the author was though,
it may be worth to note that C99 *does* allow single-line comments
delimited by //.
The correct way to invoke the C compiler in C99-mode depends, of course,
on the compiler and it enables far more features than // comments. For
GCC, the correct option to use is -std=c99. Using this program as a
test, you can check for yourself (note that the comments of the sort
shown in the following program are EXTREMELY bad style; they only serve
as a test for //-style comments):
$ cat -n foo.c
1 #include <stdio.h> // For printf()
2 #include <stdlib.h> // For EXIT_SUCCESS
3
4 int
5 main(void)
6 {
7 printf("Hello C99 world\n"); // Print a message.
8 return (EXIT_SUCCESS); // Terminate program.
9 }
Compiling in C89 mode (which does not allow // comments) gives:
$ gcc -O -Wall -std=c89 foo.c
foo.c:1:23: warning: extra tokens at end of #include directive
foo.c:2:24: warning: extra tokens at end of #include directive
foo.c: In function `main':
foo.c:7: error: syntax error before '/' token
$
Compiling in C99 mode, works as expected:
$ gcc -O -Wall -std=c99 foo.c
$ ./a.out
Hello C99 world
$
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050221165951.GA2124>
