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,2adc22b0e703907e X-Google-Attributes: gid103376,public From: Ehud Lamm Subject: Re: Representation question (void *) Date: 1999/11/17 Message-ID: #1/1 X-Deja-AN: 549604628 References: <7E47A2C771ADD211AD3C00A0C960172D01269B57@ISCPORTSEX> <80t8er$23g$1@birch.prod.itd.earthlink.net> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Complaints-To: usenet@news.huji.ac.il X-Trace: news.huji.ac.il 942823845 2963 132.64.178.45 (17 Nov 1999 07:30:45 GMT) Organization: The Hebrew University of Jerusalem Mime-Version: 1.0 NNTP-Posting-Date: 17 Nov 1999 07:30:45 GMT Newsgroups: comp.lang.ada Date: 1999-11-17T07:30:45+00:00 List-Id: |Lipscomb, Kevin wrote in message |news:7E47A2C771ADD211AD3C00A0C960172D01269B57@ISCPORTSEX... |> How would one represent the following C declaration in Ada 95? |> |> void *data; |> |> Is this just a placeholder for a pointer that should never be referenced? |> In discussing the creating of a general sort routine for any type, I recently wrote this: "Let's examine the solution used in the C standard library. The C standard library offers two interesting functions: \textbf{qsort} which is a sorting function and \textbf{bsearch} which is used for searching. They are defined as follows: \begin{verbatim} void *bsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum)) bsearch searches base[0]..base[n-1] for an item that matches *key. The function cmp must return negaitve if its first argument (the search key) is less than its second (a table entry), zero if equal, and positive if greater. Items in the array base must be in ascending order. bsearch returns a pointer to a matching item, or NULL if none exists. void qsort(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *)) qsort sorts into ascending order an array base[0]..base[n-1] or objects of size size. The comparison function cmp is as in bsearch. \end{verbatim} \par The C routines make use of a common programing trick in C. They receive ``void *'' arguments, which are taken to mean any memory address, and do the low-level pointer manipulation using the sizes supplied as parameters. \par Notice that this approach ignores type safety, since ``void *'' is simply an idiom of ``any type.'' This has disadvantages for the user of the routine, but also for the routines programmer, who must do low level pointer arithmetic, instead of using the higher level of abstraction provided by types. \par Ada provides a type safe solution, by providing \textit{generic programming} facilites,...."[1] Of course you can mimic the C coid* trick by using the unchecked programming facilies in Ada, with all their charm :-) [1] Again from "The Little Abstractionsist" Ehud Lamm mslamm@mscc.huji.ac.il http://purl.oclc.org/NET/ehudlamm <== My home on the web Check it out and subscribe to the E-List- for interesting essays and more!