Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!sri-spam!mordor!lll-tis!ptsfa!ihnp4!inuxc!iuvax!bsu-cs!dhesi From: dhesi@bsu-cs.UUCP Newsgroups: comp.lang.c Subject: static char (*b)[6]; /* an unusual declaration */ Message-ID: <761@bsu-cs.UUCP> Date: Thu, 11-Jun-87 18:51:47 EDT Article-I.D.: bsu-cs.761 Posted: Thu Jun 11 18:51:47 1987 Date-Received: Sat, 13-Jun-87 11:10:31 EDT Reply-To: dhesi%bsu-cs@iuvax.UUCP (Rahul Dhesi) Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 37 Summary: b == d but *b != *d. The April 1987 issue of DEC Professional magazine has this interesting example of possible obfuscation in C. What is the meaning of the following declaration? static char (*b)[6]; The compiler and lint checker used by the magazine columnist seem to treat the declaration of b as equivalent to char ** but the following strange things happen. main() { static char (*b)[6]; /* an unusual declaration */ static char a[] = "Hello"; char *c = a; char **d = &c; b = d; /* So b == d ... Watch. */ printf ("%s\n", *d); /* prints "Hello" */ printf ("%s\n", *b); /* prints 0 */ } Other code fragments omitted. The columnist continues, "...This means that *b is a constant and while (b) can be modified, *b never will change its original value. Thus, setting b = d does not mean that *b == *d. Also, while *b is treated as a constant (unchangeable), the value of b can vary." He goes on to ask if other C compiles do the same thing, and wonders if Ritchie had this in mind when he defined the language. On our 4.3BSD system, the above code printed the character sequence "Hello\n^H^T\n" (without quotes). On my UNIX PC (software revision 3.0) it printed "Hello\n\n". -- Rahul Dhesi UUCP: {ihnp4,seismo}!{iuvax,pur-ee}!bsu-cs!dhesi