Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!munnari.oz.au!brolga!bunyip.cc.uq.oz.au!marlin.jcu.edu.au!cpca From: cpca@marlin.jcu.edu.au (Colin Adams) Newsgroups: comp.sys.amiga.programmer Subject: Re: ANOTHER SAS C BUG Message-ID: <1991Apr4.035633.16520@marlin.jcu.edu.au> Date: 4 Apr 91 03:56:33 GMT References: <1991Apr1.050544.13878@cs.cornell.edu> <98@hdwr1.medar.com> <1991Apr2.194634.27075@cs.cornell.edu> Organization: James Cook University of North Queensland Lines: 51 In article <1991Apr2.194634.27075@cs.cornell.edu> johnhlee@cs.cornell.edu (John H. Lee) writes: >In article <98@hdwr1.medar.com> jseymour@medar.com (James Seymour) writes: >>John, you are correct in that what the original poster was complaining about >>is, indeed, a portability "bug". You are incorrect regarding your comment >>on how the string should be declared however (does this belong in the C >>newsgroup?). >> >>char *str = "hello"; /* declare a pointer to a char array, >> initialize pointer to a string */ >> >>char str[] = "hello"; /* declare a character array, initialized >> in length and contents */ >> >>BIG difference. Especially if a function in another function is told >>that str *contains* a pointer to char, when in reality it *is* the start >>of the character array itself. [I've bitten myself with that one more times >>than I'd care to count :-)]. Lastly, the amount of memory consumed is >>not the same for each. The first declaration takes up more >>memory than the second (although generally this is an insignificant >>point). Which way it should be declared depends on what the program[mer] >>needs. > Here's a real SAS C bug void main() { char *p; p = "Well lets's create a really big string here, even though" "SAS C only supports strings which are 256 bytes long, but" " with this neat new string concatenation feature you can put" " strings on several lines. Unfortunately SAS C doesn't check" " if you go over the end of the buffer like this string will," " which will cause the compiler to trash memory and " "crash somewhere. Sometimes this stuffs up the lexical " "analysis causing 'Guru trapped' requesters! " "Well it was just great fun finding this. "; } This mightn't crash SAS as I can't try it from this DECStation, but you'll get the general idea. Yes, I do intend to mail them about it... -- Colin Adams Computer Science Department James Cook University Internet : cpca@marlin.jcu.edu.au North Queensland 'And on the eight day, God created Manchester'