On 2005-02-21 19:42, Kathy Quinlan <[EMAIL PROTECTED]> 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
    $

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to