array padding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Pop

    #16
    Re: array padding

    In <c8p03b08pd@new s3.newsguy.com> Chris Torek <nospam@torek.n et> writes:
    [color=blue]
    >I ran this on a Data General Eclipse[%] and it printed:[/color]

    <snip>
    [color=blue]
    >[% Actually I do not have access to one, but this is what it might
    >print, if I remember right.[/color]

    Did anyone implement standard C on it? How about K&R C?

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email: Dan.Pop@ifh.de

    Comment

    • Chris Torek

      #17
      Re: array padding

      >In <c8p03b08pd@new s3.newsguy.com> Chris Torek <nospam@torek.n et> writes:[color=blue][color=green]
      >>I ran this on a Data General Eclipse[%] ...
      >>[% Actually I do not have access to one, but this is what it might
      >>print, if I remember right.[/color][/color]

      In article <news:c8t6fr$c4 s$23@sunnews.ce rn.ch>
      Dan Pop <Dan.Pop@cern.c h> asked:[color=blue]
      >Did anyone implement standard C on it? How about K&R C?[/color]

      I am not at all sure about Standard C. The machine I used ran
      a (somewhat bizarre and twisted variation on) 4.2BSD Unix. The
      C compiler implemented everything required to compile typical
      Unix programs. I think that covers "K&R C" and then some -- the
      compiler had enumerations and "unsigned char", for instance.

      Quite a lot of our C code had to be fixed up not to make assumptions
      about pointer formats.

      Besides the pointer trickiness, the main thing I remember about
      the Eclipse is that the output from perror() was broken. It printed
      a two digit error number, followed by no whitespace, followed by
      the string, so that one would get things like:

      prog: cannot open foo.dat: 02No such file or directory

      (I also remember something about bogus newlines, perhaps before the
      "02".)

      (This machine and the Pyramid were responsible for our group at
      the University of Maryland making numerous fixes to varous programs.
      The Pyramid found non-pointer bugs. For instance, MH used the
      interesting calling sequence "parameter passing by register
      assumption"[%], which was impossible on the Pyramid due to its
      register windows. The Pyramid also exposed all the programs that
      failed to "return 0" or "exit(0)" from main. Return values from
      functions had to be stored in register "pr0" in the register-window
      assigned to that function, and calling some other function did not
      affect one's own pr0, only one's tr0. Hence, programs that on the
      VAX returned whatever was left in r0 -- which was the return value
      from the most-recently-called function -- instead returned their
      first argument. For main(), this was the parameter argc.)

      [% An illustration, not necessarily the actual MH code and using
      ANSI C syntax rather than Classic C:

      void f1(struct S *param) {
      register int a, b;
      register FILE *some_file;
      ...
      some_file = fopen("some_pat h", "w");
      f2(param, a);
      ...
      }

      void f2(register struct S *param, register int a) {
      register FILE *fp; /* NOTE: NOT INITIALIZED! */
      ...
      fprintf(fp, "%s: %d\n", param->zig, a);
      ...
      }

      This worked on the VAX, and even the PDP-11, because the machine's
      registers were handed out in a fixed, known order. On the VAX,
      "some_file" wound up in r9; on the PDP-11 it was in r3. In each
      case, declaring "fp" third in f2() caused the C compiler to reserve
      the same register -- which still held the opened FILE *! The VAX
      C compiler gave you six registers, while the PDP-11 gave you only
      three, so the actual "parameter passing by register assumption" in
      MH was definitely in the first six "register" variables, and almost
      certainly in the first three.]
      --
      In-Real-Life: Chris Torek, Wind River Systems
      Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
      email: forget about it http://web.torek.net/torek/index.html
      Reading email is like searching for food in the garbage, thanks to spammers.

      Comment

      • EventHelix.com

        #18
        Re: array padding

        C will allow you to use a negative index. The index into an array is
        signed integer. I guess you can use negative indices if you make sure
        that the memory before the start of the array is allocated for this.

        I remember seeing use of negative in Tanenbaum's MINIX book. The
        positive indices were used as user task pids and negative indices
        were used for MINIX tasks.

        Sandeep
        --
        Sequence diagram based systems engineering and architecture design tool. Built in support for alternative scenarios and multi-tier architectures.

        EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF

        Comment

        • Al Bowers

          #19
          Re: array padding



          EventHelix.com wrote:[color=blue]
          > ... The index into an array is
          > signed integer. I guess you can use negative indices if you make sure
          > that the memory before the start of the array is allocated for this.
          >[/color]

          Doing this little trick is not C. A resource other than the
          the ISO/IEC Internation Standard may suggest this and your compiler may
          accept it in a way you expect. But that does not make it C. The C
          Language describes this as undefined behavior.

          The Standard specifically describes many circumstances of
          undefined behavor. The following circumstance seems to make operation
          clearly UB.

          — Addition or subtraction of a pointer into, or just beyond,
          an array object and an integer type produces a result that
          does not point into, or just beyond, the same array object (6.5.6).


          --
          Al Bowers
          Tampa, Fl USA
          mailto: xabowers@myrapi dsys.com (remove the x to send email)
          Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


          Comment

          • Keith Thompson

            #20
            Re: array padding

            eventhelix@hotm ail.com (EventHelix.com ) writes:[color=blue]
            > C will allow you to use a negative index. The index into an array is
            > signed integer. I guess you can use negative indices if you make sure
            > that the memory before the start of the array is allocated for this.
            >
            > I remember seeing use of negative in Tanenbaum's MINIX book. The
            > positive indices were used as user task pids and negative indices
            > were used for MINIX tasks.[/color]

            I'll bet that the "array" being indexed with a negative integer was
            actually a pointer into the middle of an array object.

            --
            Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
            San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
            We must do something. This is something. Therefore, we must do this.

            Comment

            Working...