Xref: utzoo comp.lang.c:9369 comp.arch:4357 Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!hc!beta!unm-la!unmvax!turing.UNM.EDU!mike From: mike@turing.UNM.EDU (Michael I. Bushnell) Newsgroups: comp.lang.c,comp.arch Subject: Re: Bit Addressable Architectures Message-ID: <955@unmvax.unm.edu> Date: 15 Apr 88 06:20:02 GMT References: <11702@brl-adm.ARPA> <243@eagle_snax.UUCP> <2245@geac.UUCP> <7578@brl-smoke.ARPA> <1040@mcgill-vision.UUCP> <8646@eleazar.Dartmouth.EDU> Sender: news@unmvax.unm.edu Reply-To: mike@turing.UNM.EDU.UUCP (Michael I. Bushnell) Organization: University of New Mexico, Albuquerque Lines: 109 In article <8646@eleazar.Dartmouth.EDU> major@eleazar.Dartmouth.EDU (Lou Major) writes: >*ahem* >char foo[]="This is a test."; >sizeof (foo) == sizeof (char *) >NOT the number of machine bytes/words those characters take up. (16, for most >typical installations) Perhaps people have had the POINTER == ARRAY thing hammerred into their skull too hard. According to the 4.3 BSD "C Programming Language Reference Manual, page 8 [PS1:1-8]", I find: The sizeof operator yeilds the size in bytes of its operand. (...) When applied to an array, the result is the total number of bytes in the array. The size is determined from the declarations of the objects in the expression.... But what about the compiler? Here are the results. for the code char foo1[]="This is a test."; int size1=sizeof foo1; char *foo2="This is a test."; int size2=sizeof foo2; I get: [4.3 BSD pcc]: LL0: .data .data .globl _foo1 _foo1: .long 0x73696854 .long 0x20736920 .long 0x65742061 .long 0x2e7473 .data .align 2 .globl _size1 _size1: .long 16 # NOTE: 16 for the array .align 2 .globl _foo2 _foo2: .data 2 L14: .ascii "This is a test.\0" .data .long L14 .align 2 .globl _size2 _size2: .long 4 # NOTE: 4 for the pointer [GNU C Compiler 1.18]: #NO_APP .globl _foo1 .data .align 0 _foo1: .ascii "This is a test.\0" .globl _size1 .data .align 2 _size1: .long 16 # NOTE: 16 for the array .globl _foo2 .text .align 0 LC0: .ascii "This is a test.\0" .data .align 2 _foo2: .long LC0 .globl _size2 .data .align 2 _size2: .long 4 # NOTE: 4 for the pointer Plug: Note how much easier it is to read the gcc stuff too... N u m q u a m G l o r i a D e o Michael I. Bushnell HASA - "A" division 14308 Skyline Rd NE Computer Science Dept. Albuquerque, NM 87123 OR Farris Engineering Ctr. OR University of New Mexico mike@turing.unm.edu Albuquerque, NM 87131 {ucbvax,gatech}!unmvax!turing.unm.edu!mike