comp.lang.ada
 help / color / mirror / Atom feed
* Trouble translating a C expression to Ada
@ 2001-10-18 20:16 file13
  2001-10-18 22:43 ` Jeffrey Carter
  0 siblings, 1 reply; 2+ messages in thread
From: file13 @ 2001-10-18 20:16 UTC (permalink / raw)


Howdy all,

I've been going through "Programming Linux Games"
( http://www.nostarch.com/plg.htm )
and translating the SDL examples to Ada using AdaSDL
( https://sourceforge.net/projects/adasdl/ or
http://www.adapower.net/%7Eavargas/ )
and I've run into a snag.  How would one translate this expression into Ada:

raw_pixels[offset] = pixel_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).

The original C is here:
http://www.qlippoth.com/direct-pixel-drawing-sdl.c

and what I've got so far on the Ada version is here:
http://www.qlippoth.com/direct_pixel_drawing_sdl.adb

I'm using Gnat-3.13p on Mandrake 8.1

Would SDL.Types.Increment be the correct way to do this and if so
would we require more Unchecked_Conversions?

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

The gnathtml docs are here:
http://www.adapower.net/~avargas/SDL/AdaSDLhtml/index.htm

Also, if you find any other problems please let me know.  :)

Thank you!

--
file13
http://www.qlippoth.com/





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Trouble translating a C expression to Ada
  2001-10-18 20:16 Trouble translating a C expression to Ada file13
@ 2001-10-18 22:43 ` Jeffrey Carter
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey Carter @ 2001-10-18 22:43 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-10-18 22:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-18 20:16 Trouble translating a C expression to Ada file13
2001-10-18 22:43 ` Jeffrey Carter

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