Bit Addressable Architectures
Michael I. Bushnell
mike at turing.UNM.EDU
Fri Apr 15 16:20:02 AEST 1988
In article <8646 at eleazar.Dartmouth.EDU> major at 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 at turing.unm.edu Albuquerque, NM 87131
{ucbvax,gatech}!unmvax!turing.unm.edu!mike
More information about the Comp.lang.c
mailing list