From: vanadis@cs.dal.ca (Jose Castejon-Amenedo)
Subject: Strange dicrepancy between  DECstation & Sun 4
Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
Date: Thu, 23 Jul 1992 16:30:17 GMT


	I wrote the program at the end of this message in order to get
a clear picture of what pointers are all about. First I saved it to a
file called points.c, and then I compiled it on a DECstation 5000 with
gcc 1.36 under Ultrix 4.2, and on a Sun 4/490 with gcc 1.37.1 under
SunOS 4.1.2. In both cases I simply did

	gcc points.c -o points

Now after invoking it with the command line

	points Herewith shall we show our third test

in the DECstation I get the output

	p       p       p
	points  points  points
	H       H       H
	e       e       e
	r       r       r
	ewith   ewith   ewith
	ewith   ewith   ewith
	shall   shall   shall
	t       t       t
	thall   thall   thall

as I expected. However, the same command line in the Sun bombs out as
follows:

	p       p       p
	points  points  points
	H       H       H
	e       e       e
	r       r       r
	ewith   ewith   ewith
	ewith   ewith   ewith
	shall   shall   shall
	Segmentation fault

	Can anybody please explain what's going on? Where is the bug:
in the DECstation or in the Sun? Or is it that I have utterly
misunderstood something?

	I'll be thankful for any constructive comments, which I will
summarize in due course.

JCA
vanadis@cs.dal.ca
       or
sammy@vana.physto.se


--------------------------------------------

#include <stdio.h>


main (int argc, char ** argv)
{
/* argv points to an array of strings. */

  char * strs[] = { "points", "Herewith", "shall", "we", "show",
                    "our", "third", "test" } ;

  char ** crd = strs ;

  printf ("%c\t", **argv) ;    /* Pointer unchanged.
                                  Returns 1st character 1st string. */
  printf ("%c\t", **crd) ;
  printf ("%c\n", *strs[0]) ;


  printf ("%s\t", *argv) ;     /* Pointer unchanged.
                                  Returns 1st string. */
  printf ("%s\t", *crd) ;
  printf ("%s\n", strs[0]) ;


  printf ("%c\t", **++argv) ;  /* Pointer to 1st character 2nd string.
                                  Returns 1st character 2nd string. */
  printf ("%c\t", **++crd) ;
  printf ("%c\n", *strs[1]) ;


  printf ("%c\t", *++*argv) ;  /* Pointer to 2nd character 2nd string.
                                  Returns 2nd character 2nd string. */
  printf ("%c\t", *++*crd) ;
  printf ("%c\n", *strs[1]) ;


  printf ("%c\t", *++*argv) ;  /* Pointer to 3rd character 2nd string.
                                  Returns 3rd character 2nd string. */
  printf ("%c\t", *++*crd) ;
  printf ("%c\n", *strs[1]) ;

  printf ("%s\t", ++*argv) ;   /* Pointer to 4th character 2nd string.
                                  Returns substring from 4th character
                                  2nd string to end 2nd string. */
  printf ("%s\t", ++*crd) ;
  printf ("%s\n", strs[1]) ;


  printf ("%s\t", *argv) ;     /* Pointer unchanged.
                                  Returns substring from 4th character
                                  2nd string to end 2nd string. */
  printf ("%s\t", *crd) ;
  printf ("%s\n", strs[1]) ;


  printf ("%s\t", *++argv) ;   /* Pointer to 3rd string.
                                  Returns 3rd string. */
  printf ("%s\t", *++crd) ;
  printf ("%s\n", strs[2]) ;


  printf ("%c\t", ++**argv);   /* Pointer unchanged.
                                  Replaces 1st character 3rd string by
                                  next character in character table,
                                  and then returns that. */
  printf ("%c\t", ++**crd) ;
  printf ("%c\n", *strs[2]) ;


  printf ("%s\t", *argv) ;     /* Pointer unchanged.
                                  Returns 3rd string with 1st character
                                  replaced by previous step. */
  printf ("%s\t", *crd) ;
  printf ("%s\n", strs[2]) ;

  return 0 ;
}