Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!mailrus!csd4.milw.wisc.edu!leah!rpi!pawl4.pawl.rpi.edu!entropy From: entropy@pawl.rpi.edu (Math Student from Hell) Newsgroups: comp.lang.c Subject: Taking addresses of constants Summary: You shouldn't be able to. Message-ID: <5537@rpi.edu> Date: 17 Jun 89 18:15:21 GMT Sender: usenet@rpi.edu Distribution: usa Organization: Eaters of Wisdom Lines: 43 Consider the following code: static char foo[]="\0\0\0\0\0\0\0\0"; ... { auto char **x; /* 'foo' has type (char *), so '&foo' will have type (char **) */ x = &foo; **x = 'w'; } Now, this code should be illegal and fail to compile, because 'foo' is a constant expression and so has no address. or, if the compiler allows this, it ought to stick the value of 'foo' in some static area and then generate code that assigns the address of this area to 'x' at the appropriate time. The old IBM 370 C compiler (Meaning the one that came out before last month) does neither of these things. It generates assembly code that carries out the statement x = foo; instead of x = &foo; And thus, when I execute **x = 'w';, I get a segmentation violation. Now: 1) Is this a common mistake? Is it a mistake at all? 2) What does the ANSI standard have to say about this kind of situation? Is '&foo' disallowed entirely, or does the compiler have to stuff the value of 'foo' somewhere and then give you a pointer to it? Thank you. What a wonderful thing is the human brain; how I wish I possessed one. Mark-Jason Dominus entropy@pawl.rpi.EDU entropy@rpitsmts (BITnet)