Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!kaukau.comp.vuw.ac.nz!virtue!ccc_ldo From: ccc_ldo@waikato.ac.nz Newsgroups: comp.sys.mac.programmer Subject: More on MPW C 3.0 question Message-ID: <162.25dfe4b3@waikato.ac.nz> Date: 19 Feb 90 00:25:04 GMT Lines: 91 The story so far: While porting a large C program between versions of MPW C, I came across a strange quirk in the 3.0 compiler, which is summed up in the following program: typedef unsigned char Str255[256]; main() { Str255 temps, *tempp; tempp = &temps; } When I try to compile this, the compiler throws up the following error message: # # tempp = &temps; # ? ### Error 225 Incompatible types for assignment #----------------------------------------------------------------------- File "test.c"; Line 9 #----------------------------------------------------------------------- A number of people have made the same suggestion to me, viz, replace the line tempp = &temps; with tempp = temps; Would you believe, this doesn't work? I get the exact same error, on the same line. Only one bright soul suggested the obvious, "brute force" solution--a type cast. This does work. Here is the modified program, with an extra line added to keep the compiler from optimising away the body of the routine completely: typedef unsigned char Str255[256]; main() { Str255 temps, *tempp; tempp = (Str255 *) &temps; do_something_with(tempp); } It even generates the right code. *And* taking out the ampersand, as per those other suggestions, makes no difference--it still compiles, and still generates the same code. To all those people who tried to explain to me that, in C, arrays are actually just constant pointers--thanks, but I knew that. Also, all the C compilers I've met, except one, have allowed me to use "&array" to mean the same thing as "array", where "array" was an array variable. The MPW 3.0 compiler is no exception, as the following version of the troublesome program demonstrates: typedef unsigned char Str255[256]; main() { Str255 temps; unsigned char *tempp; tempp = &temps; do_something_with(tempp); } This version also compiles without error, and generates the right code. Thanks everybody for your help. But, the question remains: is this behaviour a requirement of the ANSI C standard, or is it a bug in Apple's compiler? Lawrence D'Oliveiro Mac-hacker-in-residence Computer Services Department, University of Waikato, Hamilton, New Zealand All opinions expressed in this message are sacred to Epimetheus, the Greek god of hindsight.