🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4889

ptrs vs offsets

#4889
From: rgr
Date: Thu, 01 Oct 1987 16:32
49 lines
1997 bytes
>I'm not dead sure, but I believe that it would not be legal for
>a C compiler to implement big_array using a lookup table.  Anyone
>with hard facts care to comment?  Does the standard say what
>
>	int a[2][2];
>
>	a[ x * 2 + y ] = 0;
>
>means?  I can see arguments both ways, but it looks like it
>might be undefined under a strong-typing interpretation.
>-- 
>Steve Nuchia			Of course I'm respectable!  I'm old!
>{soma,academ}!uhnix1		Politicians, ugly buildings, and whores
>!nuchat!steve			all get respectable if they last long enough.
>(713) 334 6720				- John Huston, Chinatown

I'm not sure about the new ANSI std stuff, but in K&R, 2d arrays have to
be continuous, because when they are passed to a function, "the argument
declaration in the fucntion must include the column dimension; the row
dimension is irrelevant, since what is passed is, as before, a pointer."
(page 105).  So this must work:


main()
{    
    int i,j;
    int a[3][3];

    foo (a);
 }   

 int   foo(a)
 int a[][3];
 {
    int i,j;

    (*(a+1))[2]= 8;
 }

    
and so a must be contiguous. (by the way, it did work on my VAX)

On the previous page, it also says that "Elements are stored by rows..."
which also seems to imply continuous to me.
-- 
  +-------------------------------------------------------------------+
  |          Duke Robillard                {ihnp4!}m10ux!rgr          |
  |              Disclaimer:  I claim to live in Dis.                 |
  +-------------------------------------------------------------------+
Technical Details
Message-ID: <386@m10ux.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!homxb!mhuxt!m10ux!rgr

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!homxb!mhuxt!m10ux!rgr
From: rgr@m10ux.UUCP
Newsgroups: comp.lang.misc
Subject: ptrs vs offsets
Message-ID: <386@m10ux.UUCP>
Date: Thu, 1-Oct-87 12:32:14 EDT
Article-I.D.: m10ux.386
Posted: Thu Oct  1 12:32:14 1987
Date-Received: Sat, 3-Oct-87 10:03:02 EDT
Organization: AT&T Bell Labs, Murray Hill
Lines: 48