comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: C2Ada port to linux updated.
Date: Tue, 14 Aug 2007 23:40:56 -0700
Date: 2007-08-14T23:40:56-07:00	[thread overview]
Message-ID: <ln8x8d1err.fsf@nuthaus.mib.org> (raw)
In-Reply-To: 1187144077.372577.38190@e9g2000prf.googlegroups.com

Nasser Abbasi <nma@12000.org> writes:
> On Aug 14, 5:01 pm, Keith Thompson <ks...@mib.org> wrote:
[...]
>> That's odd.  I just tried a small test program, and gcc versions 3.2
>> and 4.0.0 also support <stdbool.h> and _Bool.
>>
>> Here's the test case:
>>
>> #include <stdbool.h>
>> _Bool obj1;
>> bool obj2;
>>
>> Save it as, say, "foo.c", feed it to "gcc -c", and see what happens.
>> Perhaps your gcc is configured and/or installed incorrectly.
>
> hi Ken;

It's Keith.

> Yes, the above works, but the c2ada uses typedefs and it includes
> _Bool in there, and that is where the problem occur.
>
> I've just reduced this problem to this simple example to help
> illustrate it:
>
> gcc -c il.h
> il.h:5: error: expected identifier before '_Bool'
>
>
> $ cat il.h
>
> #include <stdbool.h>
>
> typedef enum {
>         _Bool,    /* cvt to Boolean, Ada only, unary */
>         _UnBool,  /* cvt bool->int,  Ada only, unary */
> } node_kind_t;
[...]

gcc is quite correct to reject that.  In C99, "_Bool" is a keyword.
The code above attempts to use it as an identifier.

Some background.  There have been two ISO C sntadards, C90
(essentially identical to the ANSI C89 standard) and C99.  (There was
a minor update in 1995, but we'll ignore that.)  Almost all current C
compilers fully support C90.  Most implement various compiler-specific
extensions, but have an option to disable them.  Very few compilers
implement the full C99 standard, but many compilers implement parts of
it.

C90 doesn't have a boolean type.  C99 added a new type (and keyword)
"_Bool", a name chosen to avoid colliding with identifiers in existing
code; a new header <stdbool.h> provides "bool" as an alias for "_Bool".

gcc implements _Bool as a keyword.  In C, identifiers starting with
'_' are reserved to the implementation (the rules are slightly more
complex than that), so code outside the standard runtime library
shouldn't be using such identifiers in the first place.  That's
exactly why the C99 standard chose the name _Bool, to avoid
breaking valid code.

c2ada needs to be fixed so it doesn't use "_Bool" as an identifier,
and preferably so it doesn't use any identifiers starting with
underscores.  Possibly it needs to avoid collisions with identifiers
in the C code it processes, but that can be done by prepending some
common prefix to each identifier.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  reply	other threads:[~2007-08-15  6:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-13 10:14 C2Ada port to linux updated Nasser Abbasi
2007-08-14  4:41 ` Jerry
2007-08-14  6:36   ` Nasser Abbasi
2007-08-14 23:47     ` Keith Thompson
2007-08-15  0:01       ` Keith Thompson
2007-08-15  2:14         ` Nasser Abbasi
2007-08-15  6:40           ` Keith Thompson [this message]
2007-08-14 21:05   ` Chip Orange
2007-08-14 23:16     ` Markus E.L. 2
2007-08-24 20:11       ` Chip Orange
2007-08-15  1:15     ` Jeffrey Creem
2007-08-15  9:44       ` Nasser Abbasi
2007-08-16  2:15         ` Jeffrey Creem
2007-08-17  2:15         ` Jeffrey Creem
2007-08-19 23:00           ` Jerry
2007-08-20 12:15             ` Jeffrey Creem
2007-08-15  6:35     ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox