Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!ames!ucbcad!ucbvax!CORY.BERKELEY.EDU!dillon From: dillon@CORY.BERKELEY.EDU.UUCP Newsgroups: comp.sys.atari.st Subject: sizeof("string") Message-ID: <8704120143.AA11235@cory.Berkeley.EDU> Date: Sat, 11-Apr-87 20:43:08 EST Article-I.D.: cory.8704120143.AA11235 Posted: Sat Apr 11 20:43:08 1987 Date-Received: Sun, 12-Apr-87 06:07:33 EST Sender: daemon@ucbvax.BERKELEY.EDU Lines: 29 >>In doing this I have found two (more!) bugs in Megamax:- >> >> sizeof("anystring") returns 4 (the size of the pointer!!!!), not 10. > >Excuse me, but this doesn't sound like a bug... If you take a look at >K&R page 94, "In fact, any reference to an array is converted by the >compiler to a pointer to the beginning of the array." This means you're >taking sizeof a pointer, which is in fact 4...(Remember, in C a string >is no different from a null terminated array of characters.) Wrong, it should be 10. Remember that sizeof() is special when it comes to arrays. sizeof() always returns the effective storage. char array[32]; char *ptr; sizeof(array) -result had better be 32 The same goes for strings... sizeof("hello") -result had better be 6 (it includes the \0) But pointers, on the other hand... sizeof(ptr) -result is 4 -Matt