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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin1!goblin.stu.neva.ru!news.astraweb.com!border6.a.newsrouter.astraweb.com!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!voer-me.highwinds-media.com!post01.fr7!fx02.fr7.POSTED!not-for-mail Message-ID: <$ql0lCCpEcmTFwCt@ada-augusta.demon.co.uk> From: Mike H Reply-To: Mike Hopkins Newsgroups: comp.lang.ada Subject: A question about private types MIME-Version: 1.0 Content-Type: text/plain;charset=us-ascii User-Agent: Turnpike/6.07-M (<8j9$+PdQ77fZM5di8KxNqJQ03R>) NNTP-Posting-Host: 83.104.138.185 X-Complaints-To: abuse@demon.net X-Trace: 1402585632 83.104.138.185 (Thu, 12 Jun 2014 15:07:12 UTC) NNTP-Posting-Date: Thu, 12 Jun 2014 15:07:12 UTC Date: Thu, 12 Jun 2014 16:03:05 +0100 X-Received-Body-CRC: 853648209 X-Received-Bytes: 3692 X-Original-Bytes: 3956 Xref: number.nntp.dca.giganews.com comp.lang.ada:186862 Date: 2014-06-12T16:03:05+01:00 List-Id: ... Or, at lest, I expect the answer to be about private types. My instinct is that the package below is vulnerable to erroneous use because the "Address" component of "Cell_type" can be changed. I suspect that this vulnerability could be removed if "Grid_index_type" is made read only. I have attempted to make it a private type but it then becomes non-discrete and can no longer be used as a parameter in functions such as "Line_of". Help please! And, preferably, in a form where the new source code is sufficiently transparent to be understood when doing a "walk-through" with a C++ speaker. -- ================================================== -- This package attempts to provide type-safe elementary procedures for -- use in a problem domain in which a linear array of 81 records is to be -- mapped to, or from, 9 lines of 9, 9 columns of 9 or 9 blocks of 3x3 -- ----------------------------------------------------------------------- package Sudoku_types is type Status_type is (Predefined, Solved, Not_solved); subtype Cell_value is Character range '0'..'9'; Space : constant Cell_value := '0'; subtype Candidate is Cell_Value range '1'..'9'; type Candidature is Array (Candidate) of Boolean; subtype Count_range is Integer range 0..9; type Cell_Data is record Status : Status_type := Not_solved; Content : Cell_value := Space; Candidates : Count_range := 9; Is_candidate : Candidature := (others => true); end record; type Grid_index_type is range 1 .. 81; -- to simplify mapping in either direction each cell contains its own -- (home) address within the grid type Cell_type is record Address : Grid_index_type; -- ========== vulnerable? Data : Cell_data; end record; type Grid_type is array (Grid_index_type) of Cell_type; -- Seed each cell with its own "home" address and set the data to -- default values procedure Initialise (Grid : in out Grid_type); -- =================================================== -- A line, column or block of the grid may be mapped onto a vector type Vector_index_range is range 0..9; subtype Vector_index is Vector_index_range range 1..9; type Vector_type is array (Vector_index) of Cell_type; -- =================================================== -- Lines type Line_number is range 1..9; function Line_of (G : in Grid_index_type) return Line_number; function Line (L : in Line_number; Grid : in Grid_type) return Vector_type; -- =================================================== -- Columns type Column_number is range 1..9; function Column_of (G : in Grid_index_type) return Column_number; -- etc., etc. .......... end Sudoku_types; -- Knowledge is knowing a tomato is a fruit Wisdom in knowing not to put it in the fruit salad. Mike ;-)