From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f2513845b4ef39f X-Google-Attributes: gid103376,public From: tmoran@bix.com Subject: Re: More C Date: 2000/01/28 Message-ID: <3B9k4.122$Ro5.7388@nnrp3-w.snfc21.pbi.net>#1/1 X-Deja-AN: 578624791 References: X-Complaints-To: abuse@pacbell.net X-Trace: nnrp3-w.snfc21.pbi.net 949036479 207.214.211.194 (Thu, 27 Jan 2000 21:14:39 PST) Organization: SBC Internet Services NNTP-Posting-Date: Thu, 27 Jan 2000 21:14:39 PST Newsgroups: comp.lang.ada Date: 2000-01-28T00:00:00+00:00 List-Id: type SDL_Color is record R, G, B: C.Unsigned_Char; end record; for SDL_Color'size use 4*8; for SDL_Color use record R at 0 range 0 .. 7; G at 1 range 0 .. 7; B at 2 range 0 .. 7; end record; -- You might want to replace C.Unsigned_Char with something like -- type Intensity is range 0 .. 255; -- for Intensity'size use 8; type SDL_Color_Access is access SDL_Color; type Color_List is array(C.Int range <>) of aliased SDL_Color; type Color_List_Access is access all Color_List; type SDL_Palette is record Number_Of_Colors: C.Int; Colors: Color_List_Access; end record; I presume you really want Colors to point to a Color_List, not to a single color. Note that Colors will point to a list of N colors, where N may, or may not, equal Number_Of_Colors. So you can either ignore Number_Of_Colors (using Palette.Colors.all'length if you need the count of colors in the list) or you can have your "Indexed" function do a check that "Index in 1 .. Number_Of_Colors" or "Index in 0 .. Number_Of_Colors-1" or whatever, in addition to the automatic index check. function Indexed_Color_Access(Palette: SDL_Palette; Index: C.Int) return SDL_Color_Access is begin if Index in 1 .. Palette.Number_Of_Colors then return Palette.Colors(Index)'access; else raise Constraint_Error; end if; end Indexed_Color_Access; Depending on what you're doing, you might want: function Indexed_Color(Palette: SDL_Palette; Index: C.Int) return SDL_Color is begin if Index in 1 .. Palette.Number_Of_Colors then return Palette.Colors(Index); else raise Constraint_Error; end if; end Indexed_Color; In both of the above functions, if you really want to have type SDL_Palette_Access is access SDL_Palette; and have the functions take a parameter of Palette : SDL_Palette_Access; instead of Palette : SDL_Palette; then the rest of the function still works as written because Palette.Number_Of_Colors and Palette.Colors(Index) are equivalent to (Palette.all).Number_Of_Colors and (Palette.all).Colors(Index) Note that I've changed Color_Array to Palette, since an SDL Palette is more than just an array. If the structure of SDL_Palette as a count and a pointer isn't forced on you, of course, it would be simpler to just use the Color_List array (perhaps renaming Color_List to Palette). Then just refer to Color_Array(Index) where, e.g., Color_Array : Color_List(1 .. 17); If you really must match the memory layout of the C SDL_Palette, type Arbitrary_Color_List is array(C.Int range) of aliased SDL_Color; type Arbitrary_Color_List_Access is access all Color_List; type SDL_Palette is record Number_Of_Colors: C.Int; Colors: Arbitrary_Color_List_Access; end record; is probably your best bet. You then have to do your own index checking, just as in C, and you'll want a representation clause. It's possible in Ada to do dangerous things like address arithmetic to look at storage a certain number of bytes beyond where a particular SDL_Color is stored, but it should rarely be needed. If it is really needed, look at packages System.Storage_Elements and System.Address_To_Access_Conversions For some examples of records laid out to communicate with Windows about colors and bitmaps, see Claw (internal package Colors) and Claw.Bitmaps in the $0 version of Claw at www.rrsoftware.com