Article View: comp.sys.atari.st
Article #6639Re: C question
From: Patrick Hester
Date: Wed, 06 Dec 1989 20:12
Date: Wed, 06 Dec 1989 20:12
37 lines
1673 bytes
1673 bytes
In article <875@lzaz.ATT.COM>, hcj@lzaz.ATT.COM (HC Johnson) writes:
+ In article <8912050802.AA12717@ucbvax.Berkeley.EDU>, S61304@PRIME-A.POLY-SOUTH-WEST.AC.UK (Rat) writes:
+ >
+ > Why wont Sozobon, Lattice or any other C compiler I've tried compile the
+ > following, from K&R?
+ >
+ > main()
+ > $
+ > char fred[] = "Some string constant";
+ > <rest of routine>
+ >
+ >
+ > This has been confusing me for a while, as K&R (surely correct!) would
+ > seem to indicate that this is indeed permissible!
+
+ NO NO NO
+
+ you can have char *fred[] = "hello";
+ or
+ char fred[] = {'h','e','l','l','o','\0'};
+
+ but not
+ char fred[] = "hello";
yes you can.
it sets up an array of chars including a null.
fred then refers to the address of the first byte in the array
and fred[n] is one char.
you usually can't do this, tho, inside a function unless you
declare it static. Also, it's gotta be before any program instructions
on most compilers.
--
"We've all been used 8=8 made loud to play loud
and reused..." --<-@
"And abused." =8(/\/) rutgers!cscnj!pat
"And amused!" 8=======8 (201)-562-6533
Technical Details
Message-ID:
<564@cscnj.csc.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!rutgers!cscnj!patReferences:
<8912050802.AA12717@ucbvax.Berkeley.EDU> <875@lzaz.ATT.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!rutgers!cscnj!pat From: pat@cscnj.csc.COM (Patrick Hester) Newsgroups: comp.sys.atari.st Subject: Re: C question Summary: char fred[] = "flintstone"; Message-ID: <564@cscnj.csc.COM> Date: 6 Dec 89 20:12:57 GMT References: <8912050802.AA12717@ucbvax.Berkeley.EDU> <875@lzaz.ATT.COM> Organization: Computer Sciences Corp., Piscataway NJ Lines: 37