Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!dtgcube!ed From: ed@uunet!dtgcube (Edward Jung) Newsgroups: comp.sys.next Subject: Re: Whats wrong? Message-ID: <1989Nov29.101923.368@uunet!dtgcube> Date: 29 Nov 89 10:19:23 GMT References: <1989Nov29.014513.21386@csusac.csus.edu> Organization: The Deep Thought Group, L.P. Lines: 46 In-Reply-To: hoodr@syscube.csus.edu's message of 29 Nov 89 01:45:13 GMT In article <1989Nov29.014513.21386@csusac.csus.edu> hoodr@syscube.csus.edu (Robert Hood) writes: I ran into a little problem. I have this piece of code that works on all the Unix boxes I could try, *EXCEPT* the NeXT: [source code and other stuff deleted] Why? Am I missing a compiler option somewhere? (I just used 'cc test.c') Gnu's C compiler on the NeXT machine by default does not allow writable strings for string constants (which is what you declare implicitly by using the quotes). When you initialize a string from a constant, the string points to an unwritable area of memory. This is because the compiler will unique all the strings it finds to save initializing string storage space. To excerpt from the gcc docs: * GNU CC normally makes string constants read-only. If several identical-looking string constants are used, GNU CC stores only one copy of the string. One consequence is that you cannot call `mktemp' with a string constant argument. The function `mktemp' always alters the string its argument points to. Another consequence is that `sscanf' does not work on some systems when passed a string constant as its format control string. This is because `sscanf' incorrectly tries to write into the string constant. Likewise `fscanf' and `scanf'. The best solution to these problems is to change the program to use `char'-array variables with initialization strings for these purposes instead of string constants. But if this is not possible, you can use the `-fwritable-strings' flag, which directs GNU CC to handle string constants the same way most C compilers do. So you can either set a compiler flag or change your declaration. Note that the traditional practice is really a bad one. -- Edward Jung The Deep Thought Group, L.P. BIX: ejung 3400 Swede Hill Road NeXT or UNIX mail Clinton, WA. 98236 UUCP: uunet!dtgcube!ed Internet: ed@dtg.com