Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: bug in istrstream example? Message-ID: <724@taumet.com> Date: 11 May 91 19:30:37 GMT References: <1991May11.015836.1556@neon.Stanford.EDU> Organization: Taumetric Corporation, San Diego Lines: 24 philip@pescadero.stanford.edu (Philip Machanick) writes: >In both Lippman (p. 414) and the cfront 2.0 Library Manual (p 3.12) examples >roughly of the form > char s[] = "400" > istrstream iss (s,sizeof(s)); >appear. Presumably, sizeof is a bug (since this will always return the size of >a pointer when applied to an array), and what is really required is strlen(s) - >or should it be strlen(s)+1 to allow for the null char at the end? >Has this been fixed in later editions / printings? There is nothing to fix. An array is not converted to a pointer when it is the object of the sizeof operator, so the result of sizeof(s) is the number of elements of s times the element size. Given char *s = "hello"; s is declared as a pointer, not an array, so sizeof(s) is the size of the pointer. Given extern char s[]; sizeof(s) is illegal, since the size of s cannot be determined. -- Steve Clamage, TauMetric Corp, steve@taumet.com