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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,aa7f494bf30adbc7 X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: [newbie] simple(?) data structures From: James Rogers References: <2j1e30Fsrg8vU1@uni-berlin.de> <2jao1qFvj2rgU1@uni-berlin.de> <2jc33qFv3sitU1@uni-berlin.de> <1087475845.607135@master.nyc.kbcfp.com> Message-ID: User-Agent: Xnews/5.04.25 Date: Sat, 19 Jun 2004 02:02:46 GMT NNTP-Posting-Host: 12.73.182.15 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1087610566 12.73.182.15 (Sat, 19 Jun 2004 02:02:46 GMT) NNTP-Posting-Date: Sat, 19 Jun 2004 02:02:46 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:1678 Date: 2004-06-19T02:02:46+00:00 List-Id: Hyman Rosen wrote in news:LLuAc.45601$Xw3.8597@nwrdny03.gnilink.net: > David Starner wrote: >> Turning an index into a point has >> been standard in optimizing compilers for at least a decade. > > But if you want to call a subroutine to work on part of an array, > in C you can create a pointer into the middle of the array and > pass that, while in Ada you would need to pass both an array and > an index. That's not so easy to optimize away. > I think you misunderstand Ada array slicing. Array slicing allows you to pass only the contiguous array elements you choose to pass. Using a C pointer to any portion of an array you are faced with not knowing where the end of the array is. You must also pass a second parameter indicating the number of array elements to use starting at the address referenced by the pointer. One of the difficulties of C array manipulation is revealed when passing a pointer to the array as a function parameter. The receiving function has no knowledge if the pointer actually points to an array member. More than that, the function has no information about the size of the array being pointed to. When using C strings you have the null termination convention. Unfortunately, not all C strings are automatically null terminated. If a C string (array of char) is passed to a function using a pointer to some element of the array, the most C string handling functions will process bytes in memory until it encounters a value equalling an ASCII null character. This kind of error is easily encountered using standard C functions such as strcpy(). The function strcpy() copies a source string into a target string with no concern for the size of the target string. In fact, the value representing the target string is actually a pointer to the target string. The function will copy values into memory starting at the pointed-to address until it encounters a null character in the source string. One common error is an array bounds violation. The results of a C bounds violation are undefined. The bounds violation will not be detected by either the strcpy() routine, the C compiler, or the C run-time system. Jim Rogers