comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: Trouble translating a C expression to Ada
Date: Thu, 18 Oct 2001 22:43:18 GMT
Date: 2001-10-18T22:43:18+00:00	[thread overview]
Message-ID: <3BCF5B06.7DDB57F4@boeing.com> (raw)
In-Reply-To: FMGz7.5$7a6.89@nnrp2.sbc.net

file13 wrote:
> 
> How would one translate this expression into Ada:
> 
> raw_pixels[offset] = pixel_color;

Something along the lines of

type Raw_Pixel_Set is array (Some_Range) of Interfaces.Unsigned_16;

Raw_Pixel : Raw_Pixel_Set;
Pixel_Color : Interfaces.Unsigned_16;
Offset : ...; -- Appropriate type to index a Raw_Pixel_Set
...
Raw_Pixel (Offset) := Color;

> 
> where raw_pixels is a pointer to a SDL Uint16 type (i.e. Uint16
> *raw_pixels;)
> offset is an integer, and pixel_color is a SDL Uint16 type (not a pointer).
> 

Pointers are needed much less frequently in Ada than in C, and if you're
translating C to Ada you should take advantage of every opportunity to
eliminate pointers in the Ada version. If every pointer in the C becomes
a pointer in Ada, I see little reason for the translation.

> one of it's prototypes is:
> function Increment (
>       Pointer : Uint16_Ptrs.Object_Pointer;
>       Amount : Natural) return Uint16_Ptrs.Object_Pointer;
> pragma Inline (Increment);

This is not a prototype. This is a function specification.

-- 
Jeffrey Carter



      reply	other threads:[~2001-10-18 22:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-18 20:16 Trouble translating a C expression to Ada file13
2001-10-18 22:43 ` Jeffrey Carter [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