Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!husc6!purdue!spaf From: spaf@cs.purdue.edu (Gene Spafford) Newsgroups: comp.windows.x Subject: Re: stupid C question Message-ID: <5703@medusa.cs.purdue.edu> Date: 30 Dec 88 01:55:48 GMT References: <8812300028.AA17754@EXPO.LCS.MIT.EDU> Sender: news@cs.purdue.EDU Reply-To: spaf@cs.purdue.edu (Gene Spafford) Organization: Department of Computer Science, Purdue University Lines: 23 In article <8812300028.AA17754@EXPO.LCS.MIT.EDU> rws@EXPO.LCS.MIT.EDU (Bob Scheifler) writes: >#define foo "abcde" >Is sizeof(foo) defined to be 5, 6, or >=5? My Sun compiler gives 6, >I have a bug report claiming it should be 5, and the C manuals I have >are no help. It's 6. The string "abcde" defines 6 storage locations (the trailing null is one of them), so the size of the array so defined is 6 characters. If you do the following: int arr[3]; printf("%d\n", sizeof(arr)); you should get 3 * sizeof(int) (12 on a Sun or Vax). In general, sizeof (array_name) = (number_of_elements * sizeof_element). A literal string in a special case of this. -- Gene Spafford NSF/Purdue/U of Florida Software Engineering Research Center, Dept. of Computer Sciences, Purdue University, W. Lafayette IN 47907-2004 Internet: spaf@cs.purdue.edu uucp: ...!{decwrl,gatech,ucbvax}!purdue!spaf