comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: C Integers -> Booleans: shortcut?
Date: Mon, 29 Sep 2003 15:19:07 -0500
Date: 2003-09-29T15:19:07-05:00	[thread overview]
Message-ID: <vnh4pq61inbge6@corp.supernews.com> (raw)
In-Reply-To: x7vpthkrg0h.fsf@smaug.pushface.org

"Simon Wright" <simon@pushface.org> wrote in message
news:x7vpthkrg0h.fsf@smaug.pushface.org...
> chris <spamoff.danx@ntlworld.com> writes:
>
> > Can you (in general) import a function taking/returning a C integer
> > and treat it like a boolean for import?  Let the compiler deal with
> > the difference?
>
> With GNAT you would say
>
>   type C_Boolean is new Boolean;
>   pragma Convention (C, C_Boolean);
>
> with the meaning that 0 => False, anything else => True.
>
> For other compilers I would think you'd be better off specifying
> Interfaces.C.int and comparing to 0.

Janus/Ada automatically converts Boolean to the C equivalent for calls. We
used it in our early Windows bindings - made things quite a bit clearer.

But the point is that it isn't standard, so if you want your code to work on
other compilers, don't do that. Claw doesn't use that, for instance.

                   Randy.






      parent reply	other threads:[~2003-09-29 20:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-28 16:46 C Integers -> Booleans: shortcut? chris
2003-09-28 17:15 ` Simon Wright
2003-09-28 18:17   ` chris
2003-09-29 20:19   ` Randy Brukardt [this message]
replies disabled

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